更新时间:2021-09-26 09:40:02
我不知道为什么你有一个您的JSON标记结尾处的分号(假设您在问题中表示的内容),但如果删除了分号,则可以使用 reviver函数进行修改解析数据时。
I don't know why you have a semicolon at the end of your JSON markup (assuming that's what you've represented in the question), but if that's removed, then you can use a reviver function to make modifications while parsing the data.
var parsed = JSON.parse(myJSONData, function(k, v) {
if (k === "name")
this.key = v;
else if (k === "children")
this.value = v;
else
return v;
});