2 niulijiang niulijiang 于 2013.11.06 11:19 提问

android 开发中 json解析问题出错啊

{"msg":1,"msgbox":"返回歌手分类!","data":"[ { "rownum":"11","id":"1047","userName":"敖日格勒","picurl":"mobile1_1047_head.jpg"}, { "rownum":"12","id":"1046","userName":"敖根","picurl":"mobile1_1046_head.jpg"}, { "rownum":"13","id":"1045","userName":"阿拉腾孙德尔","picurl":"mobile1_1045_head.jpg"}, { "rownum":"14","id":"1044","userName":"阿拉腾松布尔","picurl":"mobile1_1044_head.jpg"}, { "rownum":"15","id":"1043","userName":"哈斯格组合","picurl":"mobile1_1043_head.jpg"}, { "rownum":"16","id":"1042","userName":"金花儿","picurl":"mobile1_1042_head.JPG"}, { "rownum":"17","id":"1041","userName":"李胜男","picurl":"mobile1_1041_head.jpg"}, { "rownum":"18","id":"1040","userName":"赵丹丹","picurl":"mobile1_1040_head.jpg"}, { "rownum":"19","id":"1039","userName":"张震宇","picurl":"mobile1_1039_head.jpg"}, { "rownum":"20","id":"1038","userName":"张晓燕","picurl":"mobile1_1038_head.jpg"}, { "rownum":"21","id":"1037","userName":"永胜","picurl":"mobile1_1037_head.jpg"} ]"}

JSONObject jsonObj = new JSONObject(strtest)
strtest就是上面的json格式字符串
就报错 json格式不对么。。。。
org.json.JSONException: Unterminated object at character 42 of。。。
JSONArray jsonObjs = new JSONObject(strtest).getJSONArray("data");

3个回答

u013211506
u013211506   2014.01.07 12:30
已采纳

{
"msg": 1,
"msgbox": "返回歌手分类!",
"data": [
{
"rownum": "11",
"id": "1047",
"userName": "敖日格勒",
"picurl": "mobile1_1047_head.jpg"
},
{
"rownum": "12",
"id": "1046",
"userName": "敖根",
"picurl": "mobile1_1046_head.jpg"
},
{
"rownum": "13",
"id": "1045",
"userName": "阿拉腾孙德尔",
"picurl": "mobile1_1045_head.jpg"
},
{
"rownum": "14",
"id": "1044",
"userName": "阿拉腾松布尔",
"picurl": "mobile1_1044_head.jpg"
},
{
"rownum": "15",
"id": "1043",
"userName": "哈斯格组合",
"picurl": "mobile1_1043_head.jpg"
},
{
"rownum": "16",
"id": "1042",
"userName": "金花儿",
"picurl": "mobile1_1042_head.JPG"
},
{
"rownum": "17",
"id": "1041",
"userName": "李胜男",
"picurl": "mobile1_1041_head.jpg"
},
{
"rownum": "18",
"id": "1040",
"userName": "赵丹丹",
"picurl": "mobile1_1040_head.jpg"
},
{
"rownum": "19",
"id": "1039",
"userName": "张震宇",
"picurl": "mobile1_1039_head.jpg"
},
{
"rownum": "20",
"id": "1038",
"userName": "张晓燕",
"picurl": "mobile1_1038_head.jpg"
},
{
"rownum": "21",
"id": "1037",
"userName": "永胜",
"picurl": "mobile1_1037_head.jpg"
}
]
}

这个是可以正常json解析的。。你可以把你的json复制到http://www.bejson.com/go.php?u=http://www.bejson.com/index.php
然后根据提示更改哦

Jave_
Jave_   2013.11.06 13:59

"data":"[
改成:"data":[ 同样结尾的"也去掉

a63850553
a63850553 +1
4 年多之前 回复
niulijiang
niulijiang   2014.01.17 16:07

谢谢了。 非常感谢。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!