I am using gson. And I have this:
JsonObject obj = new JsonParser().parse(["1156","1157","1160"]).getAsJsonObject();
I need to loop through that gson object to form this string at the end:1156|1157|1160
But how do I loop through a json object with gson?
Actually the structure you indicate is a
JSON Array
, not aJSON Object
that would use "{" "}" as containers:To traverse the JSON Array you would do it this way, example:
To get a value in the variable
resultado
from:In the case of your example, you can use the Google GSON classes :
and you would use
JsonArray
instead ofJsonObject
since the structure is actually a Json Array, example:To get a value in the variable
resultado
from:Check the answer and depending on that remember that the .Json response can be of two types: