How do I get Construct 2 to Parse this JSON ? PLEASE HELP :(

0 favourites
  • 6 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • This is the JSON:

    {"Row":[{"id":"1","Item_Name":"Bushfly","Image_Path":"Monsters/Bushfly.png","Quantity":"1", "Description":"It's a Monster.","Seller":"Mr. Garrison","Star_Cost":"1","Category":"Monster"},{"id":"2","Item_Name":"Jebbie","Image_Path":"Monsters/Jebbie.png","Quantity":"1", "Description":"","Seller":"","Star_Cost":"1","Category":"Monster"}]}

    I have this JSON on a String variable, now how do I get from this JSON Row[1].Item_Name ?


  • I don't have the rep to post links yet, but Google "construct 2 json" and hit the link "Example: Load data from Json to array and populate game"... I think that shows you what you need to know.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you to the both of you

    But it doesn't and wouldn't work for my JSON, my JSON contains an Array within an Array with Key Pairs

  • Use the browser object to run some javascript to set a var to the json and access it that way or use yann's json plugin.

    The first step for either is to convert the text into a valid c2 string of text. Partially covered here:

    Let's use the browser object method. The first step it to convert that json text to both a valid C2 string of text and valid javascript.

    1. paste your json text in notepad

    2. replace ' with \'

    3. replace " with '

    That gives some valid text you can put in quotes and C2 will be happy with as input.

    Next use the browser object's execute javascript action to set a variable to the json.

    "window.myjson = {'Row':[{'id':'1','Item_Name':'Bushfly','Image_Path':'Monsters/Bushfly.png','Quantity':'1', 'Description':'It\'s a Monster.','Seller':'Mr. Garrison','Star_Cost':'1','Category':'Monster'},{'id':'2','Item_Name':'Jebbie','Image_Path':'Monsters/Jebbie.png','Quantity':'1', 'Description':'','Seller':'','Star_Cost':'1','Category':'Monster'}]}"[/code:1t778izg]
    That sets a global variable "myjson" to the json.
    Next use the browser.execJs() expression every time you want to access a value.
  • R0J0hound, you are the light bringer !

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