[英]How to convert JSON Array to Javascript Object Array
I have the following JSON value pushed from the server. 我从服务器推送了以下JSON值。
result=[{"id":1492,"name":"Delhi"},
{"id":109,"name":"Coimbatore"},
{"id":576,"name":"Konni"},
{"id":525,"name":"Kottayam"}
]
I know how to convert JSON Array to Javascript Array.Here is the code below(got from stackoverflow) 我知道如何将JSON数组转换为Javascript数组。这是下面的代码(来自stackoverflow)
var locations = [];
$.each(result, function(i, obj) {
locations.push([obj.id,obj.name]);
});
I want to convert this JSON Array to a JavaScript Object Array so that I can access the values as jarray[0].id
which will give me the value 1492. Please advice 我想将此JSON数组转换为JavaScript对象数组,以便可以访问
jarray[0].id
值,这将给我值1492。
You don't need to do anything to the result
array. 您无需对
result
数组做任何事情。 Just use result[0].id
and it will evaluate to 1492
. 只需使用
result[0].id
,它将result[0].id
1492
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.