可能重複:
I have a nested data structure/JSON, how can I access a specific value?訪問二維數組JSON使用JavaScript
我現在用的是美國人口普查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數組,或將其轉換爲字符串,然後可以將其放入數組中?
如果你可以使用$ .getJSON(),而非get。 getJson自動將收到的數據轉換爲js對象。 –