Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  106] [ 5]  / answers: 1 / hits: 22723  / 12 Years ago, fri, november 16, 2012, 12:00:00

Possible Duplicate:

I have a nested data structure / JSON, how can I access a specific value?






I am using the US Census API and end up with a two dimensional json array from a jQuery.get() request. My result (data) looks like this:



[[P0010001,NAME,state,county,tract], [2703,Census Tract 4001.01,17,119,400101], [5603,Census Tract 4001.02,17,119,400102], [4327,Census Tract 4002,17,119,400200]]



It looks exactly like a two dimensional javascript array, but I cannot access it like one when I try:



var population = data;
alert(population[1][0]);


Is there a way to convert the json array into a javascript array, or to convert it to a string, which could then be put into an array?


More From » arrays

 Answers
22

Use JSON.parse:



var population = JSON.parse(data);
alert(population[1][0]);


JsFiddle: http://jsfiddle.net/6CGh8/


[#81959] Wednesday, November 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tyasiaalmap

Total Points: 294
Total Questions: 107
Total Answers: 108

Location: Libya
Member since Mon, Dec 7, 2020
4 Years ago
;