js怎样读取json里面的数据
result={"rows":[{"child":0,"count":89,"id":1,"name":"物理环境安全","objId":0,"parentId":0,"...
result=
{"rows":[{"child":0,"count":89,"id":1,"name":"物理环境安
全","objId":0,"parentId":0,"pos":0},{"child":0,"count":36,"id":2,"name":"
网络安全","objId":0,"parentId":0,"pos":0},
{"child":0,"count":28,"id":3,"name":"设备及软件系统安
全","objId":0,"parentId":0,"pos":0},{"child":0,"count":6,"id":5,"name":"管
理安全","objId":0,"parentId":0,"pos":0}]}
怎样取出里面的值呢 展开
{"rows":[{"child":0,"count":89,"id":1,"name":"物理环境安
全","objId":0,"parentId":0,"pos":0},{"child":0,"count":36,"id":2,"name":"
网络安全","objId":0,"parentId":0,"pos":0},
{"child":0,"count":28,"id":3,"name":"设备及软件系统安
全","objId":0,"parentId":0,"pos":0},{"child":0,"count":6,"id":5,"name":"管
理安全","objId":0,"parentId":0,"pos":0}]}
怎样取出里面的值呢 展开
3个回答
展开全部
var json = { contry:{ area:{ man:"12万", women:"10万" } } };
//方式一:使用eval解析
var obj = eval(json);
alert(obj.constructor);
alert(obj.contry.area.women);
//方式二:使用Funtion函数
var strJSON = "{name:'json name'}";//得到的JSON
var obj = new Function("return" + strJSON)();//转换后的JSON对象
alert(obj.name);//json name
alert(obj.constructor);
//复杂一点的json数组数据的解析
var value1 = [{"c01":"1","c02":"2","c03":"3","c04":"4","c05":"5","c06":"6","c07":"7","c08":"8","c09":"9"}, {"c01":"2","c02":"4","c03":"5","c04":"2","c05":"8","c06":"11","c07":"21","c08":"1","c09":"12"}, {"c01":"5","c02":"1","c03":"4","c04":"11","c05":"9","c06":"8","c07":"1","c08":"8","c09":"2"}]; var obj1 = eval(value1);
alert(obj1[0].c01);
//复杂一点的json的另一种形式
var value2 = {"list":[ {"password":"1230","username":"coolcooldool"}, {"password":"thisis2","username":"okokok"}], "array":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}]};
var obj2 = eval(value2);
alert(obj2.list[0].password);
展开全部
最简单的方法就是将Json字符串转成对象吧,然后通过对象读取数据
JSON.parse方法
JSON.parse方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
result.rows[0].child 结果是0 result.rows[0].name 结果是物理环境安全 result.rows[1].name 结果是 网络安全 就这样用的
更多追问追答
追问
不行啊,出现这样的错误呢
TypeError: result.rows is undefined
这个要怎样解决呢
追答
你贴上来的那个数据 是你的JS代码不。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询