我有这个JSON响应(已经解析为JSON所以不需要$.parseJSON
等):
{
"raw": {
"userAgent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36",
"os": {
"windows": true,
"mac": false,
"ios": false,
"android": false,
"linux": false,
"unix": false,
"firefox-os": false,
"chrome-os": false,
"windows-phone": false,
"ps4": false,
"vita": false,
"unknown": false
},
"browser": {
"chrome": true,
"firefox": false,
"safari": true,
"opera": false,
"ie": false,
"ms-edge": false,
"ps4": false,
"vita": false,
"unknown": false
},
"device": {
"android": false,
"ipad": false,
"iphone": false,
"ipod": false,
"blackberry": false,
"firefox-os": false,
"chrome-book": false,
"windows-phone": false,
"ps4": false,
"vita": false,
"unknown": false
},
"os_version": {
"windows-3-11": false,
"windows-95": false,
"windows-me": false,
"windows-98": false,
"windows-ce": false,
"windows-2000": false,
"windows-xp": false,
"windows-server-2003": false,
"windows-vista": false,
"windows-7": false,
"windows-8-1": true,
"windows-8": false,
"windows-10": false,
"windows-phone-7-5": false,
"windows-phone-10": false,
"windows-nt-4-0": true,
"unknown": false
}
},
"os": "windows",
"browser": "chrome",
"device": "unknown",
"os_version": "windows-8-1",
"browser_version": "43.0.2357.81"
}
我需要访问browser
和browser_version
,我的工作如下:
jsonVar.raw.browser
jsonVar.raw.browser_version
但我得到了:
{"chrome":true,"firefox":false,"safari":true,"opera":false,"ie":false,"ms-edge":false,"ps4":false,"vita":false,"unknown":false}
如何在JSON上访问这两个键?
答案 0 :(得分:4)
使用以下内容。
jsonVar.browser
jsonVar.browser_version
将返回所需的值。