我正在尝试将字符串转换为JSONArray,但是每次出现JSONException时,我都不知道如何解决问题。
[
{"color_gr":0,
"color":0,
"profil":"",
"name":null,
"role":"",
"date_last":78554,
"date_":0,"plus":78,
"did":"FlaRize",
"id":"flarize45 "
}
,
{
"color_gr":0,
"color":1,
"profil":"je suis ",
"name":"#TUEURS ",
"role":"#PROGRAMMEURSD ",
"date_last":45888888,
"date_":487,
"plus":78,
"did":"FlaRize",
"id":"gg "
}
]
这是我要转换为JSONArray的字符串
java代码: -响应=谁来自服务器。
JSONArray jsonArray = new JSONArray(response);
JSONObject jsonObject = jsonArray.getJSONObject(count);
ElementChat elementChat = new ElementChat(
jsonObject.getInt("color_gr"),
jsonObject.getInt("color"),
jsonObject.getString("profil"),
jsonObject.getString("name"),
jsonObject.getString("role"),
jsonObject.getLong("date_last"),
jsonObject.getLong("date_"),
jsonObject.getLong("plus"),
jsonObject.getString("did"),
jsonObject.getString("id")
);
我真的不知道如何在jsonArray中转换此字符串。
感谢您的帮助。
答案 0 :(得分:0)
尝试一下:
liftA
答案 1 :(得分:0)
尝试以下
作为一般事物,
ArrayList<OBJECT> yourArray = new Gson().fromJson(myjsonarray.toString(), new TypeToken<List<OBJECT>>(){}.getType());
在您的情况下,请执行以下操作
ArrayList<ElementChat> yourArray = new Gson().fromJson(jsonArray.toString(), new TypeToken<List<ElementChat>>(){}.getType());