Titanium Community Questions & Answer Archive

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

BUG: JSON.parse() does not support arrays on Android

txt = '{"a": [5,6]}';
JSON.parse(txt);

This renders it pretty much useless for me.

<rant>I tried searching to see if someone had posted about this before, but the search keeps timing out with gateway errors. I also had to log in again yet again - why is the cookie timeout so short? Please consider making it longer, or at least fix your login page so that Chrome can automatically remember my login details.
</rant>

— asked April 21st 2010 by Damien Elmes
  • android
  • bug
  • json
0 Comments

4 Answers

  • Accepted Answer

    Hey Damien

    I just recently pushed a fix for this in HEAD.. can you try a recent build from our nightly build page and let me know if that fixes your problem?
    http://drop.io/titanium_android_nightly

    — answered April 21st 2010 by Marshall Culpepper
    permalink
    0 Comments
  • After getting my DB going again with that .mp3 trick (odd it wasn't necessary in 1.2.0), your .parse() changes do appear to be working fine. Thanks for the quick response, and sorry for being a bit of a grouch - though it would be great if that login issue were fixed at one point. :-)

    — answered April 21st 2010 by Damien Elmes
    permalink
    0 Comments
  • txt = '{"a": [5,6]}';
    JSON.parse(txt);
    
    eval('('+txt+')')
    

    I'm currently encountering this same issue with Titanium SDK 1.7.2 and Android SDK Revision 12 with Titanium Studio.

    Both of the above parses return:

    [Ljava.lang.Object;@43fd4198
    

    Any help would be greatly appreciated. Thanks!

    — answered August 22nd 2011 by Matt Stacy
    permalink
    2 Comments
    • http://jira.appcelerator.org/browse/TC-223

      — commented August 23rd 2011 by Matt Stacy
    • Not a permanent fix, but in the mean time you can get around the eval and JSON.parse issues by user the Function constructor:

      (new Function('return '+txt))()
      

      — commented September 14th 2011 by Russell Munson
  • 25

    — answered June 19th 2012 by Bill Freedman
    permalink
    0 Comments
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.