我得到了一個JSON,我試圖根據值解析和排序分數。我甚至無法解析它。以下是我的JSON響應。如何在android中解析jsonArray?
[
{"scores":
{ "a":1.460211E-17,
"b":3.808661E-20,
"c":3.07329371E-14,
"d":1.02141569E-17,
"e":1,
"f":6.26432543E-12,
"g":3.75437664E-14,
"h":1.877707E-21
},
"rectangle":
{ "left":142,
"width":882,
"top":0,
"height":848
}
}
]
我試圖將字符串轉換爲JSONObject,但錯誤表示它是JSONArray。
JSONObject reader = new JSONObject(json);
JSONArray jsonArray = reader.optJSONArray("scores");
像
org.json.JSONException: Value of type org.json.JSONArray cannot be converted to JSONObject
得到錯誤,所以我認爲值已經是一個JSON陣列。我想下面的代碼...
JSONArray jsonArray = reader.optJSONArray("scores");
和
JSONArray cast = jsonResponse.getJSONArray("scores");
...但它引發以下錯誤:
cannot resolve method optJSONArray()java.lang.String)
cannot resolve method getJSONArray()java.lang.String)
你爲什麼downvote?請告訴我,我可以改善我的問題? – undefined
*類型org.json.JSONArray的值不能轉換爲JSONObject *問bazillion次...學習json基礎... *無法解決方法optJSONArray()java.lang.String)* <=明顯的字符串(或任何' jsonResponse'類型是)沒有'optJSONArray'方法... – Selvin
http://www.tutorialspoint.com/android/android_json_parser.htm –