2
I am consuming an API in my application that returns me an array of names, I created a class to assign each name to 1 instance but I am having problems to take this Jsonarray and transform into object, all the methods I tried did not work, someone knows how to do this in Java (Android) ?
public void jsonToObj(JSONArray resultadoDaPesquisa) {
try {
JSONObject jsonObject = null;
JSONArray jsonArray = resultadoDaPesquisa;
jsonObject = new JSONObject(resultadoDaPesquisa.toString());
System.out.println("resultado " + jsonObject);
} catch (Exception e) {
e.printStackTrace();
}
}
org.json.Jsonexception: Value [{"id":67377,"name":"Shiren the Wanderer 4: The Eye of God and the Devil’s Navel"}] of type org.json.Jsonarray cannot be converted to Jsonobject
Welcome to Stackoverflow Lucas. Please post an excerpt of the code you already have to get a better idea of the problem, I suggest you read this help article from the site: How to create a Minimum, Complete and Verifiable example.
– Pedro Gaspar
Lucas, edit your question by posting the code you already tried. Remember, this is a site that revolves around codes. Without them, little or no help will be able to offer you.
– StatelessDev
Edited. Now with one of several codes I tried.
– Lucas Oliveira
Lucas, it would be good to see the json. It could stick here for us!
– cpll
The Jsonarray is this: [{"id":67377,"name":"Shiren the Wanderer 4: The Eye of God and the Devil’s Navel"}] returns to me an id and a name, what you want ?
– Lucas Oliveira