How do I store a Array of JSONs inside an Array ?

Get help using Construct 2

Post » Wed Sep 30, 2015 9:37 am

This is the JSON, one of it:

{"c2dictionary":true,"data":{"id":"1","Item_Name":"BushFly","Image_Path":"h.png","Quantity":"1","Description":"Monster","Seller":"Garrison","Star_Cost":"1","Category":"Monster"}}

There will be many many more of this and I want to store them into a Single Array so that I can later extract one of the JSON out and put it into a Dictionary at a later runtime operation.

Anyone knows how to do this ?
Can Array in C2 Store JSONs or I have really hit a brick this time ?
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Wed Sep 30, 2015 4:48 pm

JSON's are just text and text can be stored in an array if that's what you're asking. If you get the text from a dictionary you can just store it in the array with the dictionary.asJSON expression. If you want to store the text directly you have to change all the " to "" or ' and then put quotes around the whole thing.

Either of these are valid c2 strings of text:
Code: Select all
"{""c2dictionary"":true,""data"":{""id"":""1"",""Item_Name"":""BushFly"",""Image_Path"":""h.png"",""Quantity"":""1"",""Description"":""Monster"",""Seller"":""Garrison"",""Star_Cost"":""1"",""Category"":""Monster""}}"

Code: Select all
"{'c2dictionary':true,'data':{'id':'1','Item_Name':'BushFly','Image_Path':'h.png','Quantity':'1','Description':'Monster','Seller':'Garrison','Star_Cost':'1','Category':'Monster'}}"
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Wed Sep 30, 2015 8:23 pm

R0J0hound, thanks for being such an awesome guy.
Now what if Mr.Garrison name is for example Gar's"a ? Would both the single quote or double quite method fail ?
and to generate this output manually in php is pretty insane :-(
B
12
S
3
Posts: 288
Reputation: 1,694

Post » Thu Oct 01, 2015 3:05 am

If you're getting it from php I'm guessing you're using Ajax or something to get it. In which case you can just set the indexes of the array with Ajax.lastdata. No manipulating of the text required.

My solution above is if you're typing the above json in directly.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 21 guests