2

可能重复:
我有一个嵌套的数据结构/JSON,我怎样才能访问一个特定的值?

我正在使用美国人口普查 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 数组,或者将其转换为字符串,然后可以将其放入数组中?

4

1 回答 1

5

使用JSON.parse

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

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

于 2012-11-16T11:09:13.663 回答