How do I get the data in an array object's As JSON value?

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I'm making a game for my client and in this game, I have to collect user's data and game scores (with their permission of course). That part is already done and what I have to do next is to send it to the backend so that the data can be saved to a server. This is where I encountered the problem, I'm using array object to save the data and array's AsJson expression to send the data.

    the problem is: AsJson sends the data like this

    while what I need to send is only what's inside the data. I've been trying but Construct 3 doesn't allow me to write AsJson.data (it will give me a syntax error). I've checked the documentation but other than using for loops, I don't see any other way to get what's inside the data property.

    Can someone help? Thanks.

    Tagged:

  • You can copy all values from the array into a JSON object, and then send JSON.ToCompactString to your server:

    The resulting string will look like this:

    {"arr": ["val1", "val2", "val3".....]}

  • I haven't tried it; I actually need the data in an array of JSON objects. I will try your solution later.

  • okay, that was close to correct but still not quite. I am sure it's because the data I saved to saveDataArr array were strings (from JSON.ToCompactString). I still send the data to the server in an array of string, what I need is to send the data in an array of objects.

    Is there any way to save an object data to an array? I've been trying but no success. using a JSON's Get expression only gives me 0.

  • Here you go - array of objects in JSON.

    dropbox.com/s/72wjywhr1qkvmmp/JSON_arrayOfObjects.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That works! I don't really understand how that saved the data to an array of objects, but it worked!

    Thanks a lot dop2000!

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