Javascript 使用属性解析JSON结果
在解码的JSON中,我还有一个子列表,其中包含:Javascript 使用属性解析JSON结果,javascript,arrays,json,Javascript,Arrays,Json,在解码的JSON中,我还有一个子列表,其中包含: "steps": [{ "id": 54785, "response": { "attributes": { "xsi:type”:”text1”},”message": { "attributes": { "xsi:type": "xsd:string" },
"steps": [{
"id": 54785,
"response": {
"attributes": {
"xsi:type”:”text1”},”message": {
"attributes": {
"xsi:type": "xsd:string"
},
"$value": "alterMultipleParameter"
},
"nextcase": {
"attributes": {
"xsi:type": "xsd:int"
},
"$value": 4823
},
"nextstep": {
"attributes": {
"xsi:type": "xsd:int"
},
"$value": 54786
},
“myid ":{"
attributes ":{"
xsi: type ":"
xsd: string "},"
$value”: ”1234”
},
"tickaction": {
"attributes": {
"xsi:type": "xsd:string"
},
"$value": "httpok"
},
"miscellaneous": {
"attributes": {
"xsi:type": "xsd:string"
},
"$value": "eyJjb250YWluZXJwZCI6ZmFsc2UsInJlYWRhYmxlQWN0aW9uIjoiYWwdWx0aXBsZUNvcnB1c1BhcmFtZXRlciBLb3JwdXNfSG9laGUgMTAwMC4wMCIsIm5leHRBY3Rpb24iOiJhZGRGcm9udCJ9"
}
}
},
{
"id": 54786….
}]
我知道如何访问步骤值及其id
for(y=0; y < myArr.finishedRuns[i].steps.length; y++)
{
console.log(myArr.finishedRuns[i].steps[y].id);
console.log(myArr.finishedRuns[i].steps[y].miscellaneous);
}
(y=0;y
{
console.log(myArr.finishedRuns[i].steps[y].id);
console.log(myArr.finishedRuns[i].步骤[y].杂项);
}
但是如何从杂项中获取值呢?目前我得到“未定义”的杂项部分。
miscellaneous.value将在错误中失败 您可以使用forEach:
steps.forEach(data => {
console.log(data.response.miscellaneous);
});
它是否正确打印id?您是否尝试过
myArr.finishedRuns[i].steps[y].miscellaneous['$value']
?myArr.finishedRuns[i].steps[y].response.miscellaneous
?编辑您的问题后,可以清楚地看到miscellaneous
属于response
,因此您需要键入myArr.finishedRuns[i].steps[y].response.miscellaneous['$value']
认为这不起作用,因为在步骤列表中。只有id和响应具有子值。你期望的结果是什么?