如何读取Json文件的数据
答案:3 悬赏:0 手机版
解决时间 2021-02-06 04:31
- 提问者网友:战皆罪
- 2021-02-05 07:45
如何读取Json文件的数据
最佳答案
- 五星知识达人网友:平生事
- 2021-02-05 08:22
var json = { contry:{ area:{ man:"12万", women:"10万" } } };<br>//方式一:使用eval解析 <br>var obj = eval(json); <br>alert(obj.constructor);<br>alert(obj.contry.area.women); <br><br>//方式二:使用Funtion函数 <br>var strJSON = "{name:'json name'}";//得到的JSON <br>var obj = new Function("return" + strJSON)();//转换后的JSON对象 <br>alert(obj.name);//json name <br>alert(obj.constructor);<br><br>//复杂一点的json数组数据的解析 <br>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); <br>alert(obj1[0].c01); <br><br>//复杂一点的json的另一种形式 <br>var value2 = {"list":[ {"password":"1230","username":"coolcooldool"}, {"password":"thisis2","username":"okokok"}], "array":[{"password":"1230","username":"coolcooldool"},{"password":"thisis2","username":"okokok"}]}; <br><br>var obj2 = eval(value2); <br>alert(obj2.list[0].password);
全部回答
- 1楼网友:痴妹与他
- 2021-02-05 09:30
读取为表格形式
- 2楼网友:忘川信使
- 2021-02-05 08:39
首先,把php数组中的数据写入json文件。
然后,把json文件中的数据读取到php变量中。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯