gpt4 book ai didi

javascript - 如何从 jsonString 中检索对象?

转载 作者:行者123 更新时间:2023-12-03 11:28:02 26 4
gpt4 key购买 nike

Web 服务正在返回 jsonString。解析后,我必须将其值绑定(bind)到表中。

最简单的方法是查找字符串中的每个对象。例如:我的字符串以以下格式返回:

{
"Table1": [
{
"ProjectId": "VS200-001---",
"day1": "---",
"day2": "---",
"day3": "---",
"day4": "---",
"day5": "---",
"day6": "---",
"day7": "---",
"day8": "---",
"day9": "---",
"day10": "---",
"day11": "---",
"day12": "---",
"day13": "4.3",
"day14": "2",
"day15": "---",
"day16": "---",
"day17": "---",
"day18": "---",
"day19": "---",
"day20": "---",
"day21": "---",
"day22": "---",
"day23": "5",
"day24": "---",
"day25": "---",
"day26": "---",
"day27": "---",
"day28": "---",
"day29": "---",
"day30": "---"
},....
]
}

解析后我得到了对象的。

for(var x=0; x< _data.Length;x++)
{
for(var dys = 0; dys< dates.Length;dys++){
var val = "day" + (dys+1);
tbody += _data[0] .val + "</tr>";
///Here exception is generating incorrect format
//but if i use here _data[0].day1 it will show the value for day1
//how to convert string to object inorder to retrieve the value

}
}

最佳答案

当使用存储在变量中的键访问对象时,您需要使用数组表示法。更改此:

_data[0].val

对此:

_data[0][val]

从代码的外观来看,您还需要关闭td

关于javascript - 如何从 jsonString 中检索对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26845219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com