How do I load array with json data

Get help using Construct 2

Post » Sat Sep 10, 2016 2:10 pm

how do i load data from a json file into an array? Having trouble following the tutorials/manual on this. I can get the data into my program, but not into the array object. My array remains empty. Can anyone give a simplified step by step way of doing it?
B
9
S
3
Posts: 31
Reputation: 708

Post » Sat Sep 10, 2016 2:39 pm

delusan wrote:.. I can get the data into my program, but not into the array object. My array remains empty. ..


Image

array.json
Code: Select all
{"c2array":true,"size":[3,1,1],"data":[[["one"]],[["two"]],[[3]]]}
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Sat Sep 10, 2016 3:07 pm

Thank you koorbach. When I run debug mode, I can see the data from the file when i click on 'ajax', but when i click 'array' the 3 array values are empty.
B
9
S
3
Posts: 31
Reputation: 708

Post » Sat Sep 10, 2016 5:19 pm

delusan wrote:Thank you koorbach. When I run debug mode, I can see the data from the file when i click on 'ajax', but when i click 'array' the 3 array values are empty.


That sounds like the array.json file was not added to the capx file.

Here's an example.

https://www.dropbox.com/s/j730z3m05rjnw ... .capx?dl=0

Explained

1. Saved array.json file to the same folder.
2. Right clicked [Files] under Projects Property and selected [Import Files].
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Sat Sep 10, 2016 6:01 pm

I've have imported the arraytext.json file into Projects/Files/icons but the array still shows only 0,0,0. Not real clear on what is meant by '1. Saved array.json file to same folder'.
B
9
S
3
Posts: 31
Reputation: 708

Post » Sun Sep 11, 2016 12:33 am

delusan wrote:I've have imported the arraytext.json file into Projects/Files/icons but the array still shows only 0,0,0. Not real clear on what is meant by '1. Saved array.json file to same folder'.


That's just one of the steps I took. I copied the json file to the same folder that contained .capx, but I don't think that's necessary.

Could you post your capx, please?
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Sun Sep 11, 2016 1:21 pm

Unfortunately, I do not know how to post the capx.
B
9
S
3
Posts: 31
Reputation: 708

Post » Sun Sep 11, 2016 3:24 pm

Hope i've done this dropbox thing right ... when i run the capx and debug, i have all 0 values in the array.

https://www.dropbox.com/s/r5tg6rae02hvz ... .capx?dl=0
B
9
S
3
Posts: 31
Reputation: 708

Post » Sun Sep 11, 2016 5:10 pm

delusan wrote:{"arraytext02":true,"size":[3,1,1],"data":[[["one"]],[["two"]],[[3]]]}

korbaach wrote:{"c2array":true,"size":[3,1,1],"data":[[["one"]],[["two"]],[[3]]]}]


not "yourFileName":true,"size":..... OR "yourArrayName":true,"size":.....

it's always c2array !!!
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Sun Sep 11, 2016 6:14 pm

Bingo! Gmoney - you led me to learning how to post a capx ... Korbaach - you found the error. Thank you guys.
B
9
S
3
Posts: 31
Reputation: 708

Next

Return to How do I....?

Who is online

Users browsing this forum: alextro, ivanski1983 and 10 guests