How do I get data back into array from database?

0 favourites
  • 2 posts
From the Asset Store
Helping streamers give their viewers more excitement.
  • I'm sending a C3 array to a (mySQL) database. Then I want to retrieve it with C3 and restore the array.

    The array is width=4, height=1, depth=1.

    Array: x(0)="rat", x(1)= "elephant", x(2)= "lion", x(3)= "sloth"

    When I send it to the database, I see it gets stored as below. Note the extra brackets (does this mean the animal names are in their own array?).

    {"c2array":true,"size":[4,1,1],"data":[[["rat"]],[["elephant"]],[["lion"]],[["sloth"]]]}

    Then I use AJAX to retrieve the data. From C3 (and when I use postman), I see the data is retrieved with escape characters.

    "{\"c2array\":true,\"size\":[4,1,1],\"data\":[[[\"rat\"]],[[\"elephant\"]],[[\"lion\"]],[[\"sloth\"]]]}"

    I'm at a complete loss on how to put the data back in the original array, so it's just like when it was stored. Any help would be very appreciated.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you tried "Array Load from JSON" action with this string received from the server?

    If it doesn't work, you should use urlencode() and urldecode() expressions. Urlencode the data before sending, and urldecode after you receive it.

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