How do I load data from JSON array to Object Array?

0 favourites
  • 9 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello,

    To make localization easier, I decided to put all text from my game project into JSON array (created in Construct 3 via Project Bar -> Files -> New -> Array).

    As I guess, to start using strings from this array in Event Sheets for Set Text action, I need to load data from this JSON into Array (as object type).

    How should I do it? Or are there any better methods to accomplish this task?

    Thanks!

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey there, the way to proceed is to use the AJAX plugin to request the content of the Json in project files, once it is complete, use AJAX.LastData expression when loading your array from Json

  • Thank you for your quick answer, but I don't get it a little, sorry.

    So, I must add AJAX object to my project, okay. Then, on start of my layout I must "Request project file" and select my JSON array.

    What should I do next, how do I transfer data to array (as object)?

  • Ok so when you request a project file, you have to specify a tag, after that AJAX has a condition to check when a tag action is complete :

    On "your tag" completed :

    YourArray > Load from Json (this is where you use AJAX.LastData expression)

  • Hello,

    I think the easiest thing would be to look at this example here: https://editor.construct.net/#open=json

    It's also really easy using Javascript:

    developer.mozilla.org/en-[url=https://www.construct.net]US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse[/url]

    It has a build in JSON.parse method which will turn your JSON string into a javascript object.

  • Ok so when you request a project file, you have to specify a tag, after that AJAX has a condition to check when a tag action is complete :

    >On "your tag" completed :

    YourArray > Load from Json (this is where you use AJAX.LastData expression)

    Thanks, It kinda worked, I used action “Load from JSON string” and “AJAX.LastData”. However, everything from JSON array goes to cell 0,0 in the Object Array.

    How can I transfer strings to their corresponding cells? Should I use loop, if yes, how?

  • That curious, usually an array's Json contain its size as well, maybe it is due to C3 array editor? I never used it so I'm not sure how it works, in C2 I used to make my array through events and then download the Json at runtime, we need someone who knows C3 better

  • That curious, usually an array's Json contain its size as well, maybe it is due to C3 array editor? I never used it so I'm not sure how it works, in C2 I used to make my array through events and then download the Json at runtime, we need someone who knows C3 better

    False alarm, my bad. Everything works great. Debugger somehow shows wrong information, but SetText works as intended.

    Thank you very much!

  • Great!

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