How do I load the data from a JSON file into an array?

0 favourites
  • 6 posts
From the Asset Store
Excel2JSON
$1.20 USD
60% off
Convert multiple Excel files into JSON files and import them into construct3.
  • I've been searching the forums for more than an hour for a solution to this seemingly simple problem but either I wasn't able to find it or the explanations I found were too complicated for me. I am new to arrays and I would like to know how I can load the data from my menu_data.json file into my empty menu_data array. I wrote the data inside the file via notepad in the exact format that construct saves JSON files. Here's what it contains:

    {"c2array":true,"size":[6,2,1],"data":[[["PreMenu"],[0]],[["StartMenu"],[0]],[["OptionsMenu"],[1]],[["CampaignMenu"],[1]],[["LevelMenu"],[3]],[["Game"],[4]]]}[/code:3pfeiu9d]
    I just want my game to load the data into the empty array when it starts. Please note that I need pretty specific instructions, I get the array concept but I'm still fuzzy on the commands. Also, I have no idea where I should place the file so the project can load it.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to use Ajax plugin to load up the file.

    Ajax:Request project file and then Ajax:On completed set array to Ajax.LastData

  • You need to use Ajax plugin to load up the file.

    Ajax:Request project file and then Ajax:On completed set array to Ajax.LastData

    I tried that but the only files I can choose there are .pngs. I found the folder where they are located and placed by .json file there but I still can't select it in the top-down list. Maybe I got the wrong folder. The only folder I found that contained the files in the list was Program Files\Construct 2\exporters\html5.

  • In your C2 project right click on the Files folder and choose "Import file" and from here select and import your json file.

  • In your C2 project right click on the Files folder and choose "Import file" and from here select and import your json file.

    Right, I knew I was missing something simple. Thank you. However I did this and nothing's happening, my array is still empty:

    Do you mean something else by "set array to Ajax.LastData"?

  • [quote:u6tr9muw]Right, I knew I was missing something simple. Thank you. However I did this and nothing's happening, my array is still empty:

    Do you mean something else by "set array to Ajax.LastData"?

    I tried it with a different array and .json file and it definitely worked. I'll figure out why the first one doesn't work. Thanks for clearing things up, now I can handle data much more efficiently.

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