is the JSON.parse included in Ti broken?
i tried to get array of objects from server and populate the result to table view,…
here's an example of the response text:
[{name: John, group: [foo, bar, baz]},
{name: Bob, group: [abc, def, ghi]}]
(i know it's missing all the quotes, but it's just an example, the real data is valid, i checked and have use it for browser extensions)
here's the result of JSON.parse
({name= John, group = (foo, bar, baz)},
{name= Bob, group = (abc, def, ghi)}; )
notice the square brackets… ergo the loop breaks and when I saved to flat file (via JSON.stringify) and reload the tableview, the app just breaks if i tap on anything…
update
i've figured it out, the loop isn't actually broken but JSON.parse is… i originally wanted to save the flat file to be a proper TableView data, so on 2nd round app launch i just need to parse the file and load the TableView… so, i just reformat after reading the file atm…
thanks anyway…
2 Answers
-
Are you testing under iOS or Android?
If Android, I noticed a comment in a code section of another project which says in part:
>Include the json2.js JSON definition, because Titanium's Android JSON function doesn't stringify arrays properly as of 1.4.2.
See the redux project at https://github.com/dawsontoth/Appcelerator-Titanium-Redux
Try it (or what it does) to see if that solves it for you. Or you could try the nightly 1.5.x beta builds, as many Android fixes will be in 1.5.x however the nightly builds are not yet considered stable. See http://developer.appcelerator.com/doc/mobile/get_continuous_builds
-
JSON parse works fine as long as I know. Maybe posting some code where you are actually using the result will help find an error ( if any:) ).
And a small piece of the json reply.