How do I access nested objects with JSON?

0 favourites
  • 5 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello. I'm having trouble getting at the inner areas such as preconditions and effects, could someone enlighten me?

  • Try using the JSON.Path reference in your loops. That should get you the key at the current loop location. It also makes the code more generic meaning it can handle more things than just chopLog. See the picture below. In the events, you can see I do a compare on the value type to see if it is an object. This is where the system would get your preconditions and events.

    Here is the example I built to figure it out.

    drive.google.com/file/d/1po9DyAyt7RhQ4upD-_h6JNZYdHLCfmas/view

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you!

    I can't seem to drill down into the arrays for preconditions for example. Is it necessary to use for loops to get there?

    The manual says for arrays to use the index but it's an array of key value pairs so I got confused.

    I also saw in the manual that you can set Paths but it's not clear to me how that works though I think it's relevant in this case

  • In your image, your preconditions are declared as Objects, not as Arrays. You would access them the same way you access the choplog object.

    Did you look at the example I uploaded? It shows the use of the path. Basically, using the example you showed, I looped through the actions. In the loop, I use JSon.Path to reference which object the loop is currently looking at. To get the sub objects of the choplog object, loop trough the entries of choplog and use JSon.Path. The path to the preconditions would be Actions.choplog.preconditions.

  • I modified the example and made it a little clearer how the sub-objects are accessed. Download it and take a look.

    drive.google.com/file/d/1po9DyAyt7RhQ4upD-_h6JNZYdHLCfmas/view

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)