在以下JSON
的本机React中,我需要获取array
的{{1}} [“ abc description”,“ def description”,“ ghi description”等]值string
。 DataHolder
中可能有n个dictionary
DataHolder
我是本机新手,将不胜感激。
答案 0 :(得分:2)
听起来像您想从API响应中重组数据。这是一种解决方案:
const data = {
...
"Response": {
"Data": {
"DataHolder": [
{
"abc": "abc description"
},
{
"def": "def description"
},
{
"ghi": "ghi description"
}
]
}
}
};
const descriptions = data.Response.Data.DataHolder.map(item => Object.values(item)[0]);
// ["abc description", "def description", "ghi description"]
答案 1 :(得分:0)
一种解决方案是使用JSON库
const tempJSON = {
"StatusCode": 200,
"Description": "Description",
"Message": "Success",
"Response": {
"Data": {
"DataHolder": [
{
"abc": "abc description"
},
{
"def": "def description"
},
{
"ghi": "ghi description"
}
]
}
}
}
let resultJSON = JSON.stringify(tempJSON)
resultJSON = JSON.parse(resultJSON)
console.log(resultJSON.Response.Data.DataHolder)
记录结果
(3) [{…}, {…}, {…}]
0: {abc: "abc description"}
1: {def: "def description"}
2: {ghi: "ghi description"}