【发布时间】:2019-09-25 00:14:22
【问题描述】:
我尝试将 JSONObject 转换为 JSONArray 并为 typeMismacth 错误出错。我试图弄清楚会发生什么,但我坚持这一点。
private void prepareReportList(String reportList) {
try {
JSONObject task_type_list = null;
try {
task_type_list = new JSONObject(reportList);
JSONArray data = task_type_list.getJSONArray("data");
int length = data.length();
for (int i = 0; i < length; i++) {
addReportData(data.getJSONObject(i));
}
} catch (JSONException e) {
e.printStackTrace();
}
} finally {
setDataValuesToView(caregiverReportList);
}
}
这是我的代码。
并且响应返回此输出,
{
"data":{
"c_correctCount":"0",
"c_total":"0",
"r_correctCount":"0",
"r_total":"0",
"p_correctCount":"0",
"p_total":"0",
"i_correctCount":"0",
"i_total":"0"
}
}
我是如何解决这个问题的。我需要将响应转换为 JSONArray。如何实现。
【问题讨论】:
-
我是如何解决这个问题的
data应该是一个 json 数组 ([...]) 而不是 json 对象 ({...}) ...(或者你应该解析它作为对象而不是数组)
标签: android json arraylist response