{
"response":{
"110":{
"location":null,
"name":"报警电话",
"type":"poi"
}
},
"responseHeader":{
"status":200,
"time":1452220774806,
"version":"1.1.0"
}
}
上述的json如何快速获取location、name、type的值,110表示的是用户输入的号码,是会变化的。
变与不变并没有区别。
变就定义成变量就行了。
var foo = 110; // 或者从用户那儿取到这个数据
var location = response[foo].location;
var name = response[foo].name;
var type = response[foo].type;
var data = {
"response":{
"110":{
"location":null,
"name":"报警电话",
"type":"poi"
}
},
"responseHeader":{
"status":200,
"time":1452220774806,
"version":"1.1.0"
}
};
$.each(data, function (index, value) {
if ("response" == index) {
$.each(value, function (index, value) {
console.log(index, value);
});
}
return true;
});