Possible Duplicate:
Parsing JSON with JavaScript
I understand to get the value of a json data, for instance var json = [{"country":"US"}]
, I can do it like json[0].country
.
I've this json data [{"0":"US"}]
, so how do I retrieve the data then?
Possible Duplicate:
Parsing JSON with JavaScript
I understand to get the value of a json data, for instance var json = [{"country":"US"}]
, I can do it like json[0].country
.
I've this json data [{"0":"US"}]
, so how do I retrieve the data then?
You could use json[0]['0']
as the "0" is just a name as far as JavaScript is concerned
Here the key of the only object into the array is string so you can access it with:
var bar = [{"0":"US"}];
console.log(bar[0]['0']); // 'US'
If I'm understanding your question correctly, it would just be
json[0]["0"]
to retrieve your data. The zero is in quotes the second time round, because it's stored as a string in your example.