我有来自邮递员的以下输出或达到终点(可以说)。
{
"SearchResult": {
"total": 11,
"resources": [
{
"id": "12345",
"name": "GuestType",
"description": "Identity group ",
},
{
"id": "56789",
"name": "Admin",
"description": "",
},
]
}
}
我想从这些值中提取
"id"
和"name"
。我看到这些值在子块内。如何使用需要放在邮递员“测试”标签中的Java脚本提取这些键值?
最佳答案
尝试
let ids = data.SearchResult.resources.map(obj => obj.id);
let names = data.SearchResult.resources.map(obj => obj.name);
let data={ "SearchResult": { "total": 11, "resources": [ { "id": "12345", "name": "GuestType", "description": "Identity group ", }, { "id": "56789", "name": "Admin", "description": "", }, ] } }
let ids = data.SearchResult.resources.map(obj => obj.id);
let names = data.SearchResult.resources.map(obj => obj.name);
console.log(ids);
console.log(names);
关于javascript - 获取键:子块内的值对,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58912909/