我有一个从应用程序前端获取的包含多个数组的JSON字符串。
String editList = [{"gradingId":"9","lowerLimit":"34","upperLimit":"55"},{"gradingId":"11","lowerLimit":"23","upperLimit":"45"},{"gradingId":"37","lowerLimit":"20","upperLimit":"35"}]
i获得单个元素
gradingId= 9
lowerLimit=34
UpperLimit=55
以此类推。
有没有一种方法可以通过那里的名称访问gradingId,LowerLimit和upperLimit?
答案 0 :(得分:1)
这将帮助您遍历数据
let editList = [{"gradingId":"9","lowerLimit":"34","upperLimit":"55"},{"gradingId":"11","lowerLimit":"23","upperLimit":"45"},{"gradingId":"37","lowerLimit":"20","upperLimit":"35"}]
editList.map(listItem => {
Object.keys(listItem).map(objItem => {
console.log(objItem +'=' + listItem[objItem])
})
})
或者如果键是预定义的。您可以避免第二个循环,并使用以下代码。
let editList = [{"gradingId":"9","lowerLimit":"34","upperLimit":"55"},{"gradingId":"11","lowerLimit":"23","upperLimit":"45"},{"gradingId":"37","lowerLimit":"20","upperLimit":"35"}]
editList.map(listItem => {
console.log("gradingId" +'=' + listItem["gradingId"])
console.log("lowerLimit" +'=' + listItem["lowerLimit"])
console.log("upperLimit" +'=' + listItem["upperLimit"])
})
答案 1 :(得分:0)
let editList = [
{"gradingId":"9","lowerLimit":"34","upperLimit":"55"},
{"gradingId":"11","lowerLimit":"23","upperLimit":"45"},
{"gradingId":"37","lowerLimit":"20","upperLimit":"35"}]
editList.forEach((list,index) => {
console.log(editList[index]);
)
您可以将forEach函数用于javascript中的数组。
答案 2 :(得分:0)
Rank Reseller = RANKX(ALL('ResellerSales'[Resellerkey]), [Sales Amount])
循环,Array方法等,以数组的形式遍历editList
。for
editList[i][key]