org.json.JSONException:值

时间:2012-07-25 09:33:46

标签: java json

JSONObject jsonObject;
try {
    int ch;
    StringBuffer b = new StringBuffer();
    System.out.println("Before second while loop");
    while((ch=is.read())!= -1) {
        b.append((char) ch);
    }
    jsonObject = new JSONObject(b.toString());
    String statusStr =  jsonObject.getString("status");
    String responseCode = jsonObject.getString("responseCode");
    Log.e("","JSON STATUS"+statusStr);
    Log.e("","JSON RESPONSE"+responseCode);

我收到错误org.json.JSONException:Value at

jsonObject = new JSONObject(b.toString());

1 个答案:

答案 0 :(得分:0)

new JSONObject(String)中的字符串应该是大括号。从{开始,以}

结束

此外,您应该在字符串中使用JSON格式的文本,例如

{"person": {"id": "1", "firstName": "first", "lastName": "last", "middleName": "middle"}, "key" : "value" }