嗨我有这个json数据
var json = { "@@lang": "en-US", "ResultSet": { "@@version": "2.0", "@@lang": "en-US", "Error": "0", "ErrorMessage": "No error", "Locale": "en-US", "Found": "1", "Quality": "99", "Results": [{ "quality": "72", "latitude": "30.778864", "longitude": "76.686648", "offsetlat": "30.778864", "offsetlon": "76.686648", "radius": "400", "name": "30.78,76.69", "line1": "30.78,76.69", "line2": "", "line3": "Mohali, Sahibzadaajit Singh Nagar, Punjab", "line4": "India", "house": "", "street": "", "xstreet": "", "unittype": "", "unit": "", "postal": "", "neighborhood": "", "city": "Mohali", "county": "Sahibzadaajit Singh Nagar", "state": "Punjab", "country": "India", "countrycode": "IN", "statecode": "PB", "countycode": "", "uzip": "", "hash": "", "woeid": "2290786", "woetype": "7"}]} };
我需要倒数第二个值--woeid:2209786
如何使用json获取此值?
{
"@@lang": "en-US",
"ResultSet": {
"@@version": "2.0",
"@@lang": "en-US",
"Error": "0",
"ErrorMessage": "No error",
"Locale": "en-US",
"Found": "1",
"Quality": "99",
"Results": [
{
"quality": "72",
"latitude": "30.778864",
"longitude": "76.686648",
"offsetlat": "30.778864",
"offsetlon": "76.686648",
"radius": "400",
"name": "30.78,76.69",
"line1": "30.78,76.69",
"line2": "",
"line3": "Mohali, Sahibzadaajit Singh Nagar, Punjab",
"line4": "India",
"house": "",
"street": "",
"xstreet": "",
"unittype": "",
"unit": "",
"postal": "",
"neighborhood": "",
"city": "Mohali",
"county": "Sahibzadaajit Singh Nagar",
"state": "Punjab",
"country": "India",
"countrycode": "IN",
"statecode": "PB",
"countycode": "",
"uzip": "",
"hash": "",
"woeid": "2290786",
"woetype": "7"
}
]
}
}
答案 0 :(得分:3)
你可以用'。'来浏览对象。运算符,因为结果在数组中使用'[]'并获得所需的对象... 试试这个。
var val=json.ResultSet.Results[0].woeid
alert(val);
答案 1 :(得分:2)
试试这个:
json.ResultSet.Results[0].woeid
答案 2 :(得分:1)
alert(json.ResultSet.Results[0].woeid);
答案 3 :(得分:1)
json.ResultSet.Results[0].woeid