{"some_id": [ {"city":"Bellevue"}, {"state":"Washington"} ] }
+3
A:
var json = {"some_id": [ {"city":"Bellevue"}, {"state":"Washington"} ] }
json.some_id[0].city
equals "Bellevue"
and
json.some_id[1].state
equals "Washington"
GerManson
2010-07-07 00:46:02
+5
A:
var theJSonString = '({"some_id": [ {"city":"Bellevue"}, {"state":"Washington"} ] })';
var x = eval(theJSonString);
alert(x.some_id[0].city); // will display "Bellevue"
DanC
2010-07-07 00:46:37
If you parse JSON with `eval`, you need to wrap the contents in parentheses (e.g. `eval('(' + theString + ')')`), otherwise it gets parsed as a block statement instead of an object literal.
Matthew Crumley
2010-07-07 02:02:05
Added missing parenthesis. Thanks @Matthew Crumley
DanC
2010-07-07 03:10:03
+1
A:
And this (the json parser and stringifier from json.org) might help :) (check the link at the bottom of the page)
Dan Heberden
2010-07-07 00:49:50