{"address_components" : [
{
"long_name" : "209省道",
"short_name" : "S209",
"types" : [ "route" ]
},
{
"long_name" : "忻城县",
"short_name" : "忻城县",
"types" : [ "sublocality", "political" ]
},
{
"long_name" : "来宾市",
"short_name" : "来宾市",
"types" : [ "locality", "political" ]
},
{
"long_name" : "广西壮族自治区",
"short_name" : "广西壮族自治区",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
]
}
------解决方案--------------------
var names = [];
for (var i = 0; i < jsonObj.address_components.length; i++) {
var addr = jsonObj.address_components[i];
for (var j = 0; j < addr.types.length; j++) {
if (addr.types[j] == 'country') {
names.push(addr.short_name);
break;
}
}
}