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):

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

但它在捕获和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);
  }

但我不认为这是一个正确的策略。

4

1 回答 1

0

您是否尝试responseTypejson. 如果问题仍然存在,这些帖子中有一些建议
JSON Parsing works on Android 4.0 but not on Android < 4.0
Issue initializing a JSONObject
JSON parsing question

于 2013-02-02T12:29:59.790 回答