将 JSON 反序列化为 JavaScript 对象
2022-08-30 00:07:29
我在使用AJAX访问的Java服务器应用程序中有一个字符串。它看起来像下面这样:
var json = [{
"adjacencies": [
{
"nodeTo": "graphnode2",
"nodeFrom": "graphnode1",
"data": {
"$color": "#557EAA"
}
}
],
"data": {
"$color": "#EBB056",
"$type": "triangle",
"$dim": 9
},
"id": "graphnode1",
"name": "graphnode1"
},{
"adjacencies": [],
"data": {
"$color": "#EBB056",
"$type": "triangle",
"$dim": 9
},
"id": "graphnode2",
"name": "graphnode2"
}];
当字符串从服务器中提取时,有没有一种简单的方法可以将其转换为活的JavaScript对象(或数组)?还是我必须手动拆分字符串并手动构建对象?