我有 JSON 格式的字符串。例如:
{
"blockedStatus":true,
"cars":[
"RAW:123",
"TVU:123"
],
"phones":[
"370665566",
"3706324231"
]
}
这是服务器的输出。我需要获得单独的值,但我不知道该怎么做。
试过这个:
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
JSONTokener tokener = new JSONTokener(builder.toString());
JSONArray finalResult = new JSONArray(tokener);
Log.e("IO-OUTPUT", builder.toString()); //prints json output
Log.e("finalResult (1)", finalResult.getString(1));
但我得到蚂蚁例外:
W/System.err(31249): org.json.JSONException: Value {"blockedStatus":true,"cars":["RAW"],"phones":["65431"]} of type org.json.JSONObject cannot be converted to JSONArray
还有另一种获取价值的方法吗?因为计算符号并从中获取值太难了