-3

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 Answer 1

0

You can parse JSON using JSON.parse();

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

const obj = JSON.parse(exampleJSON);

console.log(obj.id); // 245
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.