Titanium Community Questions & Answer Archive

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

Problem to parse JSON string

Hi, I have an issue to parse a JSON string, here is my code :

http://gist.github.com/645895

obviously something went wrong but I can't figure what.
Anyone have an idea ?

— asked October 25th 2010 by Thierry Le Moulec
  • array
  • json
  • json.parse
0 Comments

1 Answer

  • Can you be more specific? The JSON in the note is good and the output looks like what I'd expect to see based on the data. What isn't working?

    — answered October 25th 2010 by John McKnight
    permalink
    4 Comments
    • Yes, you're right. Trying to simplify the json string I've changed : "sales-by-months" by only "months" . And the problem is here, the property name with dash in it make an error when I try to read a property :

      ParsedResponse.sales-by-month[0].sales
      

      This don't work.

      — commented October 25th 2010 by Thierry Le Moulec
    • Try

      ParsedResponse["sales-by-month"][0].sales
      

      — commented October 25th 2010 by John McKnight
    • it works thanks John ;)

      — commented October 26th 2010 by Thierry Le Moulec
    • You're welcome.

      — commented October 26th 2010 by John McKnight
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.