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