load an array with JSON

Get help using Construct 2

Post » Mon Jul 29, 2013 3:51 pm

From various posts, I have guessed at the JSON format required to load an array.

Its for looking up the "th" string, e.g.

"1" & array.at(1)
should result in "1st" etc.

I tried loading it with this string:

"{
    ""c2array"": true,
    ""size"": [75,0,0],
    ""data"":[1:""st"",2:""nd"",3:""rd"",4:""th""]
}"

I also tried this:

"{
    ""c2array"": true,
    ""size"": [75,1,1],
    ""data"":[[[1:""st"",2:""nd"",3:""rd"",4:""th""]]]
}"

and this:

"{
    ""c2array"": true,
    ""size"": [75,1,1],
    ""data"":[[[""na"",""st"",""nd"",""rd"",""th""]]]
}"

and a million other formats.

The ones which dont throw a runtime error, all print "10", i.e. they get back zero from the array.

Anyone know the required JSON format to load an array (or dictionary).

Thanks!
nutmix2013-07-29 15:53:02
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Mon Jul 29, 2013 4:04 pm

OK, sussed it. The correct format is:

"{
    ""c2array"": true,
    ""size"": [75,1,1],
    ""data"":[[[""na""]],[[""st""]],[[""nd""]],[[""rd""]],[[""th""]]]
}"

Doesn't seem logical, but I guess thats JS for you!
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Thu Dec 05, 2013 4:59 pm

why do u have double double quotes or quad single quotes?

B
5
S
1
Posts: 78
Reputation: 556

Post » Thu Dec 05, 2013 8:44 pm

You need to uses double double quotes quotes to put a single double quote in a string.

It's the equivalent of using \" in other languages.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests