我无法返回 JSONArray,而是我的对象似乎是一个字符串。myArray的值与jsonString的值相同。该对象是 String 对象而不是JSONArray。以及jsonString和myArray prnt:
[{"id":"100002930603211",
"name":"Aardvark Jingleheimer",
"picture":"shortenedExample.jpg" },
{"id":"537815695",
"name":"Aarn Mc",
"picture":"shortendExample.jpg" },
{"id":"658471072",
"name":"Adrna opescu",
"picture":"shortenedExample.jpg"
}]
如何将其转换为实际的 Java JSONArray?谢谢!
//arrPersons is an ArrayList
Gson gson = new Gson();
String jsonString = gson.toJson(arrPersons);
JsonParser parser = new JsonParser();
JsonElement myElement = parser.parse(jsonString);
JsonArray myArray = myElement.getAsJsonArray();