Skip to content
Advertisement

JSON.simple – How to correctly access nested JSON objects

Example of my json file is

JavaScript

Right now I am able to get values from lenght, pool and weather. But I am stuck on how to access the nested array nested object trophy-name.

My code is:

JavaScript

This is my first time experimenting with json files so I am trying to play around with it so the code is not great.

I probably have to create new object like

JavaScript

And then from there I should be able to get the text with this?

JavaScript

Even if I that is correct I am not sure how to implement it into the loop or if there is better way to do the loop? Dont mind redoing the code differently and any advice appreciated.

Advertisement

Answer

Yes, you are right, simply extract the JSONObject within the loop and then get the required fields.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement