0

嗨,我有这个 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 获取此值?


更新/编辑(格式化 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"
            }
        ]
    }
}
4

4 回答 4

3

您可以使用 '.' 浏览对象。运算符,并且由于结果在数组中,因此使用“[]”并获取所需的对象...试试这个。

var val=json.ResultSet.Results[0].woeid
alert(val);
于 2013-01-17T07:45:57.810 回答
2

试试这个:

json.ResultSet.Results[0].woeid
于 2013-01-17T07:46:14.880 回答
1

使用这种方式:

alert(json.ResultSet.Results[0].woeid);
于 2013-01-17T07:46:27.250 回答
1
json.ResultSet.Results[0].woeid
于 2013-01-17T07:47:11.993 回答