How To Get Json object inside json object

52 Views Asked by At

My code snippet for nested json object:

JsonArray arr = jsonObject.getAsJsonArray("data");
for(int i = 0; i < arr.size(); i++) {
    String _Id =  arr.get(i).getAsJsonObject().get("_id").getAsString();
    String Name = arr.get(i).getAsJsonObject().get("name").getAsString();
    int Trips = arr.get(i).getAsJsonObject().get("trips").getAsInt();
}
1

There are 1 best solutions below

0
On

You can parse JSON using JSON.parse();

let exampleJSON = '{ "id": 245, "name": "Mike" }';

const obj = JSON.parse(exampleJSON);

console.log(obj.id); // 245