Reputation: 21
I have an array and when i try to parse it gives me
com.google.gson.internal.LinkedTreeMap
cannot be cast to [Ljava.lang.Object;
Array Example :
System.out.print(getObject().toString());
**[{msgid=2105630801, Sender=Z001}]**
I have already tried that code snippet
ArrayList arrayList = (ArrayList) getObject();
Iterator iterator = arrayList.iterator();
System.out.println("List elements : ");
while (iterator.hasNext()) {
Object[] objects = (Object[]) iterator.next();
for (Object object : objects) {
System.out.print("@@@" + object);
}
System.out.print(iterator.next());
}
Upvotes: 2
Views: 58
Reputation: 40078
The below JSON is JSONArray
with JSONObject
were JSONObject
implements Map
[{msgid=2105630801, Sender=Z001}]
So you can convert it into List<Map<Object, Object>>
List<Map<Object, Object>> list = (List<Map<Object, Object>>) getObject();
list.forEach(map->map.forEach((k,v)-> System.out.println(k+"..."+v)));
Upvotes: 1