Titanium Community Questions & Answer Archive

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

JSON.stringify() differences between Android and iPhone

The following:

  var data = { 
    'user' : { 
      'email' : emailField.value, 
      'password' : passwordField.value 
    }
  };
  parsed = JSON2.stringify(data);

Yields different results between Android(1.6 and 2.1) and iPhone(3.1) simulators (Titanium mobile 1.0). On the Android, all of the quotes around the keys and values are escaped with a backslash, whereas on the iPhone there are not.

I found that if I included the json2.js reference code from json.org, the results are inline with the iPhone results.

Anyone have any idea why the two platforms would be so different?

— asked March 24th 2010 by Mitch Shields
  • android
  • iphone
  • json
0 Comments

2 Answers

  • When the stringify'd content is sent to our server, it rejects it from the Android as malformed JSON because the keys are not encapsulated in quotes.

    — answered March 24th 2010 by Mitch Shields
    permalink
    0 Comments
  • Is it causing problems with parsing or just looks different? We're using code in the Android SDK to convert to JSON. It's from json.org.

    — answered March 24th 2010 by Don Thorp
    permalink
    1 Comment
    • Another difference that I found was that calling JSON.stringify() with a boolean argument returns the boolean literal on iOS but a quoted string on Android.

      — commented May 15th 2011 by Paul Mietz Egli
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.