function main(message){
...
phone= JSON.parse(message.phoneNumbers);
... }
我的输入JSON是
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
},
{
"type": "mobile",
"number": "123 456-7890"
}
],
"children": [],
"spouse": null
}
我收到的结果是省略了“phoneNumbers”,但我确实想要它。
答案 0 :(得分:1)
你的数据是正确的,当我JSON.parse它,我得到一切都好。
但您似乎无法以正确的方式访问您的数据。你必须首先解析整个JSON,然后你有一个javascript对象,只有这样你才能访问你的属性。
详细说明:
var obj = JSON.parse(message);
var phone = obj.phoneNumbers;
或简称:
var phone = (JSON.parse(message)).phoneNumbers;