Load JSON String Into Dictionary

Get help using Construct 2

Post » Sat Aug 18, 2012 9:06 am

Hello, does anyone know of a way to get this JSON string:

{"0":"20","1":"2","2":"6","7":"29"}

Into a Dictionary Object? I thought it might of been the Load Action but I may have been incorrect.

Any tips on getting the string above into a dictionary?

Thanks!

-T
Epic Space Online - Google it!
B
34
S
10
G
5
Posts: 165
Reputation: 6,637

Post » Sat Aug 18, 2012 2:39 pm

Try saving JSON out the Dictionary object and inspecting the result. It uses its own slightly different format. Make your JSON in the same format and it should load just fine.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sat Aug 18, 2012 5:52 pm

[QUOTE=Ashley] Try saving JSON out the Dictionary object and inspecting the result. It uses its own slightly different format. Make your JSON in the same format and it should load just fine.[/QUOTE]

I did think of that. I get the below "Syntax Error."

Let me know if i'm missing something.

I used:
{"c2dictionary":true,"data":{"5":1}}

And:
"{"c2dictionary":true,"data":{"5":1}}"

Taurian2012-08-18 18:17:49
Epic Space Online - Google it!
B
34
S
10
G
5
Posts: 165
Reputation: 6,637

Post » Sat Aug 18, 2012 7:44 pm

Double-quotes start and end strings in Construct 2 expressions, so you can't paste it in like that. You need to use this:

"{""c2dictionary"":true,""data"":{""5"":1}}"

because "" turns in to a single " inside a string. It might be easier to save it to a text file, import the text file to the project, and AJAX request it. See using project files.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Sat Aug 18, 2012 8:03 pm

[QUOTE=Ashley] Double-quotes start and end strings in Construct 2 expressions, so you can't paste it in like that. You need to use this:

"{""c2dictionary"":true,""data"":{""5"":1}}"

because "" turns in to a single " inside a string. It might be easier to save it to a text file, import the text file to the project, and AJAX request it. See using project files.[/QUOTE]

That did it. Thanks again.
Epic Space Online - Google it!
B
34
S
10
G
5
Posts: 165
Reputation: 6,637

Post » Thu Sep 25, 2014 6:09 pm

Hello,
How would the json dictionary string be if i want to insert a json array ?

Thanks
B
3
Posts: 2
Reputation: 179

Post » Thu Sep 25, 2014 6:27 pm

pnunez wrote:Hello,
How would the json dictionary string be if i want to insert a json array ?

Thanks

It would be:
Code: Select all
array.asjson
B
27
S
8
G
4
Posts: 553
Reputation: 4,839

Post » Mon Sep 29, 2014 8:13 pm

@DuckfaceNinja

Thank you very much
B
3
Posts: 2
Reputation: 179


Return to How do I....?

Who is online

Users browsing this forum: Lof, YoHoho and 21 guests