下面的这个json串。我该怎么去解析啊。。。
求代码。。我老是解析不出来或者解析错。。。
能直接解析成对象的,不是解析成JSONObject对象。。。
{"id":259,"displayImageUrl":"http:\/\/res2.aduu.cn\/union\/img\/201308\/16110341_G4uN.gif","description":"1234156","name":"专业、诚信、高效、便捷,留学首选品牌:金吉列!","packagename":"com.zhuamob","TrackingUrl":{"showUrl":["http:\/\/api.adcome.cn\/v1\/evt?sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259&appver=1.0&sdkver=1.0&evttype=1"],"clickUrl":["http:\/\/api.adcome.cn\/v1\/evt?sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259&appver=1.0&sdkver=1.0&evttype=2","http:\/\/proxy-beta.zhuamob.com?data=%7B%22status%22%3A%224%22%2C%22web%22%3A%7B%22app_user_id%22%3A213701%2C%22app_id%22%3A1767%2C%22ad_id%22%3A100003%2C%22ad_user_id%22%3A100003%2C%22price%22%3A10%2C%22ad_type%22%3A4%2C%22imei%22%3A%22862873023463216%22%2C%22mac%22%3A%22ec%3A17%3A2f%3A9d%3A5d%3A34%22%2C%22url%22%3A%22%22%2C%22show_type%22%3A%221%22%7D%7D&t=d8b217068cbc5de0795bd8c3fbf"],"installUrl":["http:\/\/api.adcome.cn\/v1\/evt?sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259&appver=1.0&sdkver=1.0&evttype=3"]},"actionType":"2","type":"4","actionUrl":"http:\/\/121.199.2.166:8080\/ad\/adwap\/0701a\/index.jsp?sno=zhuamao&media_id=debugdis01&adId=259"}
------解决方案--------------------
你解析出来的对象是不是JsonObject?
而不是一个实际的对象?
{"id":259,。。。}
这其实外面还应该有一个对象的来包含的,这里就叫ad吧
这帖子我以前好像见过一个类似的。
如果你想创建ad形式的对象,那么就需要去建一个ad的类,ad类下面包含id,http等等信息。
像TrackingUrl这样的,那么这又是一个对象,那么就需要为TrackingUrl这个对象在创建一个类,同样包含里面的信息等等。。。
给一个类似的解析方式吧:
http://bbs.csdn.net/topics/390337723
------解决方案--------------------
没有jar 。用 js 测试时没有问题。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
var t={
"id": 259,
"displayImageUrl": "http:\/\/res2.aduu.cn\/union\/img\/201308\/16110341_G4uN.gif",
"description": "1234156",
"name": "专业、诚信、高效、便捷,留学首选品牌:金吉列!",
"packagename": "com.zhuamob",
"TrackingUrl": {
"showUrl": ["http:\/\/api.adcome.cn\/v1\/evt?
sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259
&appver=1.0&sdkver=1.0&evttype=1"],
"clickUrl": ["http:\/\/api.adcome.cn\/v1\/evt?
sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259
&appver=1.0&sdkver=1.0&evttype=2", "http:\/\/proxy-beta.zhuamob.com?data=%7B%22status%22%3A%224%22%2C%22web%22%3A%7B%
22app_user_id%22%3A213701%2C%22app_id%22%3A1767%2C%22ad_id%22%3A100003%2C%22ad_user_id%22%3A100003%2C%22price%22%
3A10%2C%22ad_type%22%3A4%2C%22imei%22%3A%22862873023463216%22%2C%22mac%22%3A%22ec%3A17%3A2f%3A9d%3A5d%3A34%22%2C%
22url%22%3A%22%22%2C%22show_type%22%3A%221%22%7D%7D&t=d8b217068cbc5de0795bd8c3fbf"],
"installUrl": ["http:\/\/api.adcome.cn\/v1\/evt?
sourceid=zhuamao&appid=debugdis01&uuid=862873023463216ec:17:2f:9d:5d:3400000&reqid=4wqq345txtdldr4o&nettype=1&adid=259
&appver=1.0&sdkver=1.0&evttype=3"]
},
"actionType": "2",
"type": "4",
"actionUrl": "http:\/\/121.199.2.166:8080\/ad\/adwap\/0701a\/index.jsp?sno=zhuamao&media_id=debugdis01&adId=259"
};
var subObj=t.TrackingUrl;
for (var i in subObj){
alert(i+"-->"+subObj[i]);
}
for (var i in t){
alert(i+"-->"+t[i]);
}
});
</script>
</head>
<body>
</body>
</html>