json解析常见异常


(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 。。。)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM