可能重复:
I have a nested data structure / JSON, how can I access a specific value?
我使用的是美国Census API,最终得到了来自jQuery.get()请求的二维json数组。我的结果(数据)如下所示:
[["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"]]
它看起来就像一个二维javascript数组,但是当我尝试时我无法像访问它一样:
var population = data;
alert(population[1][0]);
有没有办法将json数组转换为javascript数组,或者将其转换为字符串,然后将其放入数组中?
答案 0 :(得分:4)
使用JSON.parse
:
var population = JSON.parse(data);
alert(population[1][0]);
JsFiddle:http://jsfiddle.net/6CGh8/