Chào mọi người . Mình muốn lấy dữ liệu từ file Json như thế này :
Nhưng bị báo lỗi là Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path
Đây là code của mình.
public static List<Notification> bindNotifyData(List<JsonElement> list)
{
List<Notification> results= new ArrayList<>();
for(JsonElement item:list)
{
JsonElement data = item.getAsJsonObject().get("updates");
JsonObject dataJsonObj = data.getAsJsonObject();
JsonArray notifyJsonArray = dataJson.get("updates").getAsJsonArray();
//ArrayList<Notification> notifyList = new ArrayList<>();
if(notifyJsonArray != null && notifyArray.size() > 0) {
for(int i = 0; i < notifyJsonArray.size(); i++) {
JsonObject notifyJson = (JsonObject) notifyJsonArray.get(i);
Notification notification = new Notification();
notification.setContent(notifyJson.get("content").getAsString());
notification.setTime(notifyJson.get("time").getAsString());
// priceHtml.setExtras(priceHtmlJSon.get("extras").getAsString());
results.add(notification);
}
}
}
return results;
}
M.n có thể xem và giúp mình được không ạ . Cảm ơn m.n nhiều