Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:51:12+00:00 2026-05-22T20:51:12+00:00

I’m writing an iPhone app at the moment using Appcelerator’s Titanium. One of the

  • 0

I’m writing an iPhone app at the moment using Appcelerator’s Titanium. One of the requirements of the app is to be able to retrieve a JSON array of recently played songs, and display this in a tableView.

I have a separate tab in the app that parses JSON from twitter without a problem, however no matter what I do, I cannot get appcelerator to parse my generated json.

The JSON is generated by a PHP file located on my server using json_encode();

This is my json:

[
    {
        "title": "Cramp Pres. Sliders - Meteor"
    },
    {
        "title": "Progressiver pres. FineSky - Fine Sky"
    },
    {
        "title": "Armin Van Buuren #x26; DJ Shah feat. Chris Jones - Going Wrong (Alex M.O.R.P.H #x26; Woody Van Eyden Remix)"
    },
    {
        "title": "Bart Claessen - Hartseer"
    },
    {
        "title": "Will Holland feat. Jeza - Start Again (Juventa Remix)"
    }
]

I’ve checked this with numerous JSON validators just to be sure, and it is indeed valid.

This is my JS:

var loader = Ti.Network.createHTTPClient();
loader.setTimeout(10000);

loader.open("GET","http://myurl.com/service/played.json");

loader.onload = function()
{
    // Ti.API.info writes information to the debug console.
    Titanium.API.info('Loaded! Status: ' + this.status);
    Titanium.API.info('Response Header: ' + this.getResponseHeader('Content-Type'));
    Titanium.API.info('Response Text: ' + this.responseText);
}

loader.send();

In the app though, the responseText is simply coming back as [] – That’s it. Nothing else. I’ve inspected the structure of my JSON and the JSON that the twitter API returns, and both seem to be layed out pretty much the same, only the twitter API is coming back with a lot more info as you can imagine.

Here are the steps I have tried:

  1. I saved the PHP generated JSON into a text file called “test.json” and attempted to parse it.. This worked fine!

  2. Previously the web service I was writing required an ?action=played query string. I removed this to ensure I was definately retreiving a JSON array. This made no difference

  3. I have sent headers in PHP for text/plain AND application/json to no avail

  4. Finally, I have employed mod_rewrite on my server so I can serve the output from the web service as a json file.. I.e. played.json — Still, an empty array.

I just feel like i’m repeatedly banging my head against a brick wall, and would appreciate some insight from some less stressed people 🙂

Any help would be greatly appreciated!

Kind Regards,

Dave

More information:
I’ve found by inspecting the http headers that the content-length returned is always 2. However, viewing the page in the browser, or the generated .json file, shows a full JSON array.

As previously suspected, this seems to be coming down to a PHP related issue now. The way the script works is simple. It queries a MySQL table to retrieve a list of songs. While it’s looping through the array it populates an array called $songs

At the end of the function, I simply use:

echo json_encode($songs);

Even more info
If I remove the content-type header and view the page in the browser, I receive the JSON array.. If I then copy that and paste it into the end of my PHP file, after the closing tag, the data I paste in is displayed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:51:13+00:00Added an answer on May 22, 2026 at 8:51 pm

    Thanks for the answers everyone.

    I have investigated further and found that the problem seemed to lie with the way my PHP script was creating the JSON array.

    Although the JSON validated, and was visible both in the browser and in the .json file I was generating, for some reason it wasn’t being created? Really strange, and I still cannot get my head around it.

    However, I decided the problem may of lay within the way I was parsing the XML feed that provided the song information. Funnily enough, it did. The code I had previously used on my website, works perfectly, but appcelerator didn’t like it one little bit.

    So I took the XML feed and ran it through simplexml_load_string() and was able to use that directly in php’s json_encode() function. BAM.. It worked.

    Thanks for the time u guys put in, it’s really appreciated!

    Dave

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.