list 类型的json数据
var source = ["10004","1234","4","3","1.5","0.5"] var res= JSON.parse(source ); res[0] 10004 res[1] 1234
对象类型的json数据解析
var source = {"uid":0,"userId":"124","username":小李","dept_id":"8"}; var res= JSON.parse(source ); res["userId"] 124 res["username"] 小李
构建JSON对象
var ret = [true,false,true,true,true,false,1,2,3,4,101,99]; var json = JSON.stringify(ret);
举例
var response = {"users":[{"id":1,"nick":"fuck1"}]}; var jsonData = JSON.parse(response); var data = jsonData["users"]; if(data){ var len = data.length; for(var i=0; i<len; i++){ var id = data["id"]; } }
时间: 2024-10-17 20:21:10