我如何使用javascript或jquery
从这种类型的对象中获取值 {
authResponse: {
userID: "12345678912345",
accessToken:"kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
session_Key: true,
expiresIn: "5183738",
sig: "..."
},
status: "connected"
}
我想从此对象获取会话密钥的值。我尝试在JSON中解析它,但这是无效的JSON格式,当我尝试使用obj.key获取值时返回undefined。我在检查会话时得到了这个回复。请通过以下链接了解更多详情
https://github.com/Wizcorp/phonegap-facebook-plugin/blob/a5c6be9/README.md
答案 0 :(得分:1)
var obj = JSON.stringify({
authResponse: {
userID: "12345678912345",
accessToken: "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
session_Key: true,
expiresIn: "5183738",
sig: "..."
},
status: "connected"
});
alert(obj.authResponse.userID); //"12345678912345"
alert(obj.status); //"connected"
答案 1 :(得分:0)
假设您想要访问每个级别的值: -
myobj = {
authResponse: {
userID: "12345678912345",
accessToken:"kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
session_Key: true,
expiresIn: "5183738",
sig: "..."
},
status: "connected"
}
alert(myobj.authResponse.userID);//"12345678912345"
alert(myobj.status);//"connected"
如果密钥是数字使用arry表示法[]
,否则点(.
)可以帮助您访问孩子。