1
I am trying to convert a Jsonobject item into an Arraylist and for that I created this function from an example I saw here in the forum:
public static ArrayList<Produto> converte(JSONObject jsonObject){
ArrayList<ArrayList> array = new ArrayList<>();
String stringJSON = jsonObject.toString();
JsonParser jsonParser = new JsonParser();
JsonObject jObject = (JsonObject) jsonParser.parse(stringJSON);
JsonArray jAProdutos = jObject.getAsJsonArray("produtosFavoritos");
ArrayList<Produto> arrayProdutos = gson.fromJson(jAProdutos,ArrayList.class);
return arrayProdutos();
}
But you’re making a mistake:
java.lang.Classcastexception: com.google.gson.Jsonprimitive cannot be cast to com.google.gson.Jsonarray
JSON:
{"produtosFavoritos":"[]",
"listas":"[]",
"estabelecimentosFavoritos":"[]",
"email":"teste",
"experiencia":0,
"nome":"teste",,
"senha":"teste",
"nivel":1}
You can put the json you are parsed?
– Sorack
I added in the question
– Éowyn
So the problem is that your arrays are quotation marks
– Sorack