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

0 favourites
  • 4 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • 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 ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    "{""c2dictionary"":true,""data"":{""id"":""1"",""Item_Name"":""BushFly"",""Image_Path"":""h.png"",""Quantity"":""1"",""Description"":""Monster"",""Seller"":""Garrison"",""Star_Cost"":""1"",""Category"":""Monster""}}"
    [/code:honoehc0]
    [code:honoehc0]"{'c2dictionary':true,'data':{'id':'1','Item_Name':'BushFly','Image_Path':'h.png','Quantity':'1','Description':'Monster','Seller':'Garrison','Star_Cost':'1','Category':'Monster'}}"
    [/code:honoehc0]
  • 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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)