• JS解析JSON


    解析JSON对象

    var people = {
    	"name": "zhangsan",
    	"age": 18,
    	"address": "beijing"
    };
    
    var json = eval('(' + people + ')');
    console.log(json.name);
    console.log(json.age);
    console.log(json.address);
    

    解析JSON数组

    var arr = [{
    			"name": "zhangsan",
    			"age": 18,
    			"address": "beijing"
    		}, {
    			"name": "lisi",
    			"age": 19,
    			"address": "shanghai"
    		}, {
    			"name": "wangwu",
    			"age": 17,
    			"address": "hangzhou"
    		}];
    for (var i in arr) {
        console.log(arr[i]);
        console.log(arr[i].name);
        console.log(arr[i].age);
        console.log(arr[i].address);
    }
    
    • 如果是字符串形式的需要使用eval函数。
    var ev = eval('(' + data + ')');
    for(var i in ev){
        cosole.log(ev[i]);
    }
    
  • 相关阅读:
    Java基础回顾---JVM&JDK&JRE
    学习
    学习
    学习
    进度
    进度
    毕设进度
    学习进度
    Beta阶段项目总结
    第二阶段冲刺——seven
  • 原文地址:https://www.cnblogs.com/dch0/p/11445012.html
Copyright © 2020-2023  润新知