How do I Read a JSON File in C2?

Get help using Construct 2

Post » Tue Feb 03, 2015 7:29 pm

Hello, I am stumped on this part and I need some help. I want an array of data (lat, long, distance, name) that can be read as a JSON file. I need help making the file and it needs to be very organized as I plan to have lots of data. It would be very helpful if I could make it look like this example:
"Data":[
{"Lat":"1", "Long":"11"},
{"Lat":"2", "Long":"12"},
{"Lat":"3", "Long":"13"}
]

But then I don't understand how to get Construct to read the sections(e.g. Data[0].Lat) by name.
Is this the wrong approach? How would you make an organized JSON file like the example that can be read by construct?

I'm completely lost so thanks for any help!
~ Bucktoothfrog
B
4
Posts: 12
Reputation: 224

Post » Tue Feb 03, 2015 8:25 pm

You are missing...
{
Code: Select all
"c2array":true,
"size":[13,6,1],
"data":[[


I added a small tut months ago... it should steer you in the right direction.
load data from json to array and populate game card

If you want organized, and are dealing with huge amount of data... this is a gem
c2 data editor
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
63
S
16
G
9
Posts: 1,429
Reputation: 12,603

Post » Thu Feb 05, 2015 7:19 am

Do you know if construct 2 uses a specific format in json? Can i use any syntax with json and still make it work? Also, how do i access a label in the events page? I want to have a column named lat and access it by lat[0] or something like that. Thanks for the help!
B
4
Posts: 12
Reputation: 224

Post » Thu Feb 05, 2015 8:18 am

Yes it does.
I would create a your array (just a few) in construct then download to json. Then use what I did and load it, then you can add all your data to that json file using the correct format.
I attached a json file to the tut - you can look at what it should look like.

Something like this
Code: Select all
{
"c2array":true,
"size":[x,y,z],
"data":[[

["00"],
["1"],
["11"]
],[
["01"],
["2"],
["22"]
],[
["02"],
["3"],
["33"]

]]
}
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
63
S
16
G
9
Posts: 1,429
Reputation: 12,603

Post » Fri Feb 27, 2015 8:42 pm

I bought the C2 Data Editor and it works great! My only issue is I need a simple "tag" to access my array column names. For example, If{Array.At(Lat) & Array.At(Long) = 20}.
Basically I want to access the array values with a word, not Array.At(3,0,1), for example. Is there any way I can do this? Thanks for all the help!
B
4
Posts: 12
Reputation: 224

Post » Fri Feb 27, 2015 9:58 pm

@bucktoothfrog - I just added this plugin. It will probably work for what your looking for. It supports loading raw JSON directly into it and accessing the data via named indexes.

https://www.scirra.com/forum/plugin-storage-3d-dictionary_t125861
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Sun Mar 08, 2015 7:51 pm

[quote="troublesum"]@bucktoothfrog - I just added this plugin. It will probably work for what your looking for. It supports loading raw JSON directly into it and accessing the data via named indexes.

I can't seem to understand how to add an index to a column name. Can you please give an example?
B
4
Posts: 12
Reputation: 224

Post » Sun Mar 08, 2015 8:10 pm

I need to try Troublesums plugin but I've been happy with forum/ plugin-json-import-export-generate-edit-inspect_t100042
B
9
S
2
Posts: 54
Reputation: 638

Post » Sun Mar 08, 2015 11:03 pm

@bucktoothfrog - The purpose of this plugin was to get away from index values and access data via names. if you can modify how you input your data into this plugin to contain only JSON objects with named keys instead an Array that is indexed it should work fine

try loading this (Notice the "0" and "1" are strings)

{"Data":{"0":{"lat":1,"long":11},"1":{"lat":2,"long":12}}}

You can then retrieve the values using the get action

Storage.get("Data","0","lat") = 1
Storage.get("Data","0","long") = 11
Storage.get("Data","1","lat") = 2
Storage.get("Data","1","long") = 12
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Mon Mar 09, 2015 3:21 pm

I see. But how do I import my already written JSON file from "C2 Data Editor" into a readable format for your plugin?
B
4
Posts: 12
Reputation: 224

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest