ajax异步加载解析复杂json(集合中包含对象,对象中包含对象)数据

时间:2022-03-06 15:35:36

1.例如后台返回的json数据如下

[{'id':"1","name":"2","user":{"name":"2","age":"18"}},{'id':"2","name":"2","user":{"name":"2","age":"18"}}]

2.前台解析代码如下

var obj = eval(s);
进行格式的转化,然后就能采用点运算符去取值,如obj[0].user.name;取出结果是2