前台遍历JSON里的map!!急

前台遍历JSON里的map!!急,第1张

var jsonObj = {"pagination":{"currentPage":2,"dataList":[{"appId":"2","cusId":"0","id":310030,"ipAddress":"192.168.1.147","logMess":"RunApp","logTime":"2013-12-06T11:04:24","logType":"1"},{"appId":"2","cusId":"0","id":310038,"ipAddress":"192.168.1.147","logMess":"RunApp","logTime":"2013-12-06T11:04:26","logType":"1"},{"appId":"1","cusId":"0","id":310039,"ipAddress":"192.168.1.147","logMess":"RunApp","logTime":"2013-12-06T11:04:26","logType":"1"}],"maxResult":20,"pageSize":10,"pages":51,"skipResult":10,"total":504}}

var dataList = jsonObj["pagination"].dataList

for(var i=0,j=dataList.lengthi<ji++){

    var oneData = dataList[i]

}

oneData就是遍历出来的值

如果是js中遍历使用

var anObject = {one:1,two:2,three:3}//对json数组each

$.each(anObject,function(name,value) {

})

如果是Java代码直接用for循环就行了,说白了json也是数组的一种,json对象和json数组都可以

//遍历json数组

String json1 = "{data:[{name:'Wallace'},{name:'Grommit'}]}"

jsonObjSplit = new JSONObject(json1)

JSONArray ja = jsonObjSplit.getJSONArray("data")

for (int i = 0i <ja.length()i++) {JSONObject jo = (JSONObject) ja.get(i)System.out.println(jo.get("name"))}

//JSONObject遍历json对象

String json2 = "{name:'Wallace',age:15}"

jsonObj = new JSONObject(json2)

for (Iterator iter = jsonObj.keys()iter.hasNext()) {String key = (String)iter.next()System.out.println(jsonObj .getString(Key))}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6710144.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-27
下一篇 2023-03-27

发表评论

登录后才能评论

评论列表(0条)

保存