2013-02-02 74 views
0
 try { 
     BufferedReader reader = new BufferedReader(new InputStreamReader(
       is, "utf-8"), 8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while ((line = reader.readLine()) != null) { 
      sb.append(line + "\n"); 
     } 
     is.close(); 
     json = sb.toString(); 
    } catch (Exception e) { 
     Log.e("Buffer Error", "Error converting result " + e.toString()); 
    }  
// try parse the string to a JSON object 
    try { 
     // convert string to jsonObject 
     Log.d("JSON Parser", "json: "+json); 
     jObj = new JSONObject(json); 

    } catch (JSONException e) { 
     Log.e("JSON Parser", "Error parsing data " + e.toString()); 
    } 

Log.d("JSON Parser", "json: "+json);給作爲輸出(logcat的)工作:Json的工作很好的在Android ICS,但不上2.3

02-02 12:08:31.371: D/JSON Parser(407): json: {"code":64,"message":"Segnalazione avvenuta con successo"} 

,但它在catch去在logcat中我讀:

02-02 12:08:31.371: E/JSON Parser(407): Error parsing data org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject 

這項工作中的Android ICS很不錯,但不工作的Android 2.3

編輯:我

解決
if (result.startsWith("[")) 
    { 



    } 
    else 
    { 
     result= result.substring(1); 
    } 

但我不認爲這是一個正確的策略。

+0

一些建議你嘗試過將其改爲'sb.append(行+ 「\ n」)之後;''到sb.append(線);' –

+0

我試過但沒有任何變化 – Atomico

回答

相關問題