ldcf.net
当前位置:首页 >> JS解析JSON字符串 >>

JS解析JSON字符串

var result={"Category":[{"categoryId":1,"categoryName":"饮品","categoryImage":"/upload/yinpin.jpg"},{"categoryId":2,"categoryName":"食品","categoryImage":"/upload/shiping.jpg"},{"categoryId":3,"categoryName":"酒类","categoryIma...

var str = '{"rows":[{"ID":0,"登录账号":"admin","登录时间":"\/Date(1446772997000)\/","登录地点":"河北石家庄","登录IP":"115.181.15.99"}]}'; var obj = eval("(" + str + ")"); console.log(obj);

将json对象返回页面。页面解析 如页面拿到var test = {name:"123",script:"alert('123')"}的json对象。 然后解析出脚本test.script; 调用js的eval()方法执行。--------eval(test.script);

一、JSON字符串转换为JSON对象 要使用上面的str1,必须使用下面的方法先转化为JSON对象: //由JSON字符串转换为JSON对象 var obj = eval('(' + str + ')'); 或者 var obj = str.parseJSON(); //由JSON字符串转换为JSON对象 或者 var obj = JSON....

var result={"Category":[{"categoryId":1,"categoryName":"饮品","categoryImage":"/upload/yinpin.jpg"},{"categoryId":2,"categoryName":"食品","categoryImage":"/upload/shiping.jpg"},{"categoryId":3,"categoryName":"酒类","categoryIma...

var data1 = "[{ value: '3017', label: '3017:有机磷农药,液体的,有毒的,易燃的'},{ value: '3018', label: '3018:有机磷农药,液体的,有毒的'}]";json1 = eval("(" + data1 + ")");alert(json1[0].label);alert(json1[1].label);

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'}";//得到的...

function countJson(json){ if("" == json){ return false; } var obj = eval("("+ json +")"), len=obj.length, result=new Array(); for(var i=0;i 0){ return result; } return '统计无结果';} var a = '[{"id":1,"name":"1"},{"id":2,"name"...

第一种 JSON.parse(jsonString) 第二种 eval("("+jsonString+")") 第三种 var obj=(function ToJSON(o){ if(typeof(o)=="string")try{return new Function("return "+o)();}catch(e){return null;} })("[{name:'zhangsan',age:'24'},{name:'lisi...

var result={"Category":[{"categoryId":1,"categoryName":"饮品","categoryImage":"/upload/yinpin.jpg"},{"categoryId":2,"categoryName":"食品","categoryImage":"/upload/shiping.jpg"},{"categoryId":3,"categoryName":"酒类","categoryIma...

网站首页 | 网站地图
All rights reserved Powered by www.ldcf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com