Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Trying to parse JSON/XML - works fine on iPhone, not on Android

Okay, I'm trying to pull data from the ReadItLater API and parse it and dump it to a table. Pretty simple stuff, right. I've removed the Ti.API.info lines I'm using for debugging and I'm not going to share my RIL user info, but you're welcome to play with my API key, if you want.

Here's my code:

var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
    var data = JSON.parse(this.responseText);

    var itemList = data.list;
    var x = 0;

    for(var i in itemList)
        var thisItem = itemList[i];
        Ti.API.info('Article Title: ' + thisItem.title);
xhr.open('POST', 'https://readitlaterlist.com/v2/get');
    format:        'json',
    username:    '--username--',
    password:    '--password--',
    apikey:        '7f5dfZc6T730xy6aobA2e66Sb7gdk507'

Now, when I run this on the iPhone, it'll return the actual title nodes in the JSON tree, but on Android it returns null (the list object being undefined).

Any idea what's going on? I was up all night trying to figure this out and came up with nothing so I'm hoping you guys can help. Thanks in advance!

— asked July 27th 2010 by Alexander Stone
  • android
  • json
  • titanium.network
  • xhr

2 Answers

  • Accepted Answer

    Shouldn't it be / try :

    var data = eval('('+this.responseText+')');

    instead of:

    var data = JSON.parse(this.responseText);

    Then see what you get if you output:

    — answered July 27th 2010 by Kosso
    • THANK YOU, KOSSO! This fixed it!

      — commented July 27th 2010 by Alexander Stone
    • [RESOLVED] I don't understand why, but eval fixed the issue..
      I even tried conn.setHeaderRequest('Content-Type','application/json; charset=utf-8'), where conn is a Ti.Network.createHttpClient() - but in vain.

      — commented May 1st 2012 by Abhitesh Das
    • THANK YOU . I had the same problem and this fixed it .

      — commented December 25th 2012 by Keith Wilson
    • Thank you. I encounter exactly the same problem too. JSON.parse() works well on iPhone but no on Android. This is so weird.

      — commented April 17th 2014 by Andrew Tse
  • Have you tried with a new build from our CI server?

    Our continuous integration (CI) system provides updated builds approximately 30 minutes or less after a change has been committed to github. Please refer to our Continuous Builds for Download guide for obtaining one for your platform.

    — answered July 27th 2010 by Don Thorp
    1 Comment
    • I have not. I'll try that and get back to you. Until then, I'm going to leave this unanswered, just in case someone sees something I'm overlooking. I'll report back once I've gotten CI set up and tested.

      — commented July 27th 2010 by Alexander Stone
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.