所以我有这个JSON结构,我想访问:
data { payload: "{"state":{"reported":{"measuredata":{…
JSON.parse不起作用,JSON.stringify也不起作用。
我只能访问有效载荷,如果我再往前走,我会收到错误或未定义:
data.payload // works
data.payload["state"] //undefined
data.payload.state // undefined
data.payload[0].state // undefined
data.payload[0]["state"] // undefined
我做错了什么?
答案 0 :(得分:3)
我能看到的是你的json data { payload: "{"state":{"reported":{"measuredata":{…
它会在有效载荷payload: "{"state"
你必须有这样的东西
payload: {"state"
答案 1 :(得分:0)
您只需将getUrl(opts:PhotoOptions)
用于JSON.parse
json字符串值。
payload
答案 2 :(得分:0)
解析的示例代码。
var data = {
"logged_in":true,
"town":"Dublin",
"state":"Ohio",
"country":"USA",
"products":
{
"pic_id":"1500",
"description":"Picture of a computer",
"localion":"img.cloudimages.us/2012/06/02/computer.jpg",
"type":"jpg",
"childrenimages":
{
"pic_id":"15011",
"description":"Picture of a cpu",
"localion":"img.cloudimages.us/2012/06/02/mycpu.png",
"type":"png"
}
}
};
var data1 = JSON.stringify(data);
var data_final = JSON.parse(data1);
console.log(data_final.products.pic_id);