首页 > Web开发 > 详细

json解析常见异常

时间:2015-07-25 19:46:53      阅读:541      评论:0      收藏:0      [点我收藏+]

(1) :

org.json.JSONException: Expected a ‘,‘ or ‘}‘ at 80 [character 81 line 1]

 
原因:出现乱码了, 导致json格式出错..
 
解决方法:
 String result = new String(data,"utf-8");
   默认是iso8859-1
(将编码方式改为utf-8)
 
if(response.getStatusLine().getStatusCode()==200){
            HttpEntity httpEntity = response.getEntity();
            byte[] data = EntityUtils.toByteArray(httpEntity);
            String result = new String(data,"utf-8");
            jsoncCallBack.response(result);
            
        }  
 
 
 
 (2) :
java.lang.IllegalArgumentException: Malformed escape pair at index 86: http://sns.maimaicha.com/api?apikey=b4f4ee31a8b9acc866ef2afb754c33e6&format=json&page=%d&rows=20&method=news.getListByType&type=16
    at java.net.URI.create(Unknown Source)
    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
    at http.HttpUtils.downloadData(HttpUtils.java:37)
    at test.Test2.main(Test2.java:31)
Caused by: java.net.URISyntaxException: Malformed escape pair at index 86: http://sns.maimaicha.com/api?apikey=b4f4ee31a8b9acc866ef2afb754c33e6&format=json&page=%d&rows=20&method=news.getListByType&type=16  
 
 
原因:URL语法异常
&format=json&page=%d 
 
解决方法:
这里这个 后面%d 应该改为数字(例如1 。。。)

 

json解析常见异常

原文:http://www.cnblogs.com/dean-Li/p/4676419.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!