How do I save an Array in an Array?

  • Hello,

    I have a question to Arrays in C3:

    I made a function to save some Userstats in a mysql database.

    To load these data, I just make an AJAX request and the answer will be a C3-Array like this:

    {"c2array":true,"size":[10,1,1],"data":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[[0]]]}

    So I do something like this:

    "myLoadArray = load from JSON string AJAX.lastdata"

    Then I can access all the data from the "myLoadArray".

    This works fine.

    But now my problem:

    I also save complete arrays...

    For example in array.at(9) I stored a full array, then it would look like this:

    {"c2array":true,"size":[10,1,1],"data":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[["{"c2array":true,"size":[10,1,1],"data":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[[0]]]}"]]]}

    And this doesn't work. I pretty sure the problem are the quotation marks.

    But how can I fix that? Working with "'" + """ like this:

    {'c2array':true,'size':[10,1,1],'data':[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[['{"c2array":true,"size":[10,1,1],"data":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[[0]]]}']]]}

    also doesn't work...

    Thanks for your help!

  • Maybe it would be easier to store the arrays in a Dictionary as strings, or you can store array data as strings, in the array and get the data with tokenat expression?

  • Embedding a JSON string inside another string requires the correct escaping of quotes. JSON must use double quotes ("), single quotes are not allowed. If you're pasting it in a Construct expression then double quotes must be doubled to "" to count as a single character, and not the character that ends the string expression. If you're using it as JSON then " must be escaped as \" inside another string.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey,

    thank you for the help!

    So the response from the AJAX-Call should look like this?

    {"c2array":true,"size":[10,1,1],"data":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[["{\"c2array\":true,\"size\":[10,1,1],\"data\":[[[7]],[[6]],[[7]],[[3]],[[7]],[[0]],[[7]],[[0]],[[6]],[[0]]]}"]]]}

    And then I can do this:

    myArray = load from JSON string AJAX.lastdata

    myArrayInArray = load from JSON string myArray.At(9)

    Should this work?

    Best regards and thank you!

    Edit:

    Tested it like described above and it worked :)

    Thank you for the help!

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