How do I import a .json file to an array???

0 favourites
  • 6 posts
From the Asset Store
Source code, art assets and music tracks to remake this game
  • On my lunch break today I created a .json file and tried to use AJAX to populate an array. It's not working and for the life of me I can't figure out why.

    Here's what I'm doing:

    1. I created a .json file using c2array format. (See below.)

    2. I imported the .json file to the Files area.

    3. On Start of Layout I use AJAX to request the file.

    4. When the .json file is Completed I Load (into the Array) from JSON string "AJAX.LastData"

    When I run in debug mode I can see the .json text in LastData, but my array has 10 values and they are all 0.

    A minute ago, as a test, I downloaded the array to a .json file, added that to my project files, tweaked a couple of values and tried again. That's not working either, for some reason. Is it an encoding issue on the text file? According to Notepad++ I'm using UTF-8.


    	"c2array": true,
    	"size": [100, 1, 1],
    	"data": [
  • How did you create your json file? Generally speaking, you're not supposed to "type" it out. You get Construct arrays in json format by using the array.asjson expression or the array download action.

    Basically there is probably a mistake in your json format somewhere. Everything else you are doing sounds about right.

  • Post a capx. Your format works - I just tried it. Must be something else, or there is a typo somewhere in the missing (etc) data.

    Keep in mind, 0 to 100 is 101 elements, not 100.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the help. Here's a link to my capx (below). I'm probably doing something stupid and will soon feel like an idiot... <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":-)" title="Smile">

  • I'm probably doing something stupid and will soon feel like an idiot...

    Yes, I think you will

    You put AJAX.LastData in quotes.

    Simply remove the quotes.

  • <sigh>

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