Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
104 stars 83 forks source link

Multidimensional Arrays in JSON #8107

Closed CrackHub closed 1 week ago

CrackHub commented 2 weeks ago

Problem description

Cannot access nested arrays with "for each" in JSON.

Attach a .c3p

nestedJSONarray.c3p.zip

Steps to reproduce

  1. run project and look browser logs.

Observed result

Return empty value

Expected result

Return array values in JSON. image

More details

Affected browsers/platforms: Chrome

First affected release:

System details

View details PASTE HERE
F3der1co commented 2 weeks ago

if I set the path like this it works image as well as this works image

so I guess this line is only referring to setting the json.path expression and not the relative path? image

AshleyScirra commented 1 week ago

I think this is just a mistake in your events. In the not working version, you have For each entry in "Array". In the first iteration of that, the current path will be "Array.0". Then the sub-event does For each entry in ".0". Therefore that will iterate the path "Array.0.0", which is actually the string "Blue" and so it doesn't iterate it as it's a string and not an object or array.

So in the subevent you want something that means "the current path being iterated" rather than ".0" which means "the first array element in the current path being iterated". Using For each entry in JSON.Path is the correct way to do that.