[Solved]Load and save to JSON

0 favourites
From the Asset Store
Match the similar cards with each other and free all animals!
  • Well basically it's for an prototype of a media application. We store data (text, filename if relevant, filepath if relevant and info like that) into an json. That's the reason why we want to import json files into our project, to follow our data structure.

    However, are multidimensional arrays within the scope of C2 Json?

  • Arrays in C2 are all 3-dimensional. No more, no less. So it should be ok.

  • Arrays in C2 are all 3-dimensional. No more, no less. So it should be ok.

    I'm terribly sorry to bother you again..

    Now I have this JSON

    {"c2array":true,"size":[10,1,1],"data":[[["Test1"]],[["Test2"]],[["3"]],[[40]],[[5.0]],[[60000]],[[7,0]],[[8.000.000]],[[9*10]],[[10]]]}[/code:usizcc2k]
    
    I load this into my project with AJAX and (try to ) parse this into my array. When I call Array.At(0) I get an 0 back. What would be the correct way to call from the array say the 2nd position? (Array.At(1) I guess right?)
    
    Error is fixed. Anyhow, how can I populate instance variables with JSON data at index 0, 1 etc etc? That's more or less the question.
    
    This is all run from preview btw.
    
    Edit: Also from my own server (using an export) I get nothing.
  • To be more percise: I call the AJAX command to pull in the JSON. However, when I set "Text to AJAX.LastData" , I get an empty text container. This makes me think that there is something in the data retrieval that doesn't work.

  • Let's go for another example but first some things :

    • use the "Debug layout" feature. This way, you can check in the console the content of an array without having to display it. Same goes the AJAX.LastData
    • in C2, an error we all do at first : if a text object isn't big enough to write its text, it will cut after the last word it can display. In your case, 1 word only (no spaces) too big => no display. It works perfectly.
    • your json has some values C2 doesn't accept, like 8.000.000. It can't load your array from JSON and doesn't raise any errors.

    So I did an example, where, check the events :

    • events 1-3 : I load an array and do some debug on it to display every data it holds. (this part isn't active)
    • event 4-5 : I populate manually an array with the datas you wanted, and download it to check the format of the JSON

    So to sum up :

    • don't display big ass texts in little objects
    • don't use unsuported types in array (stick with int, float and string)
  • Guizmus

    Just want to say i have read this thread and not only learned stuff myself but have been amazed at your patience . Thanks

  • spongehammer

    Happy to help ^^ I didn't think I coumld still teach you something though, you seem to know C2 like the back of your hand

    As for patience, when the one needing help does efforts to try and understand what you explain, it's always easier !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry for the day silence, I've been absent (dentist and birthday and stuff xD) Indeed Guizmus , patience is something you certainly have

    And I have to ask for a little bit more patience...

    {"c2array":true,"size":[2,1,1],"data":[[["test1"],["test2"]]]}[/code:3azz1ccf]
    
    This is my JSON as I am still figuring out the ins and outs before I push this to our development cycle. The array is named List, and List.At(1) returns 0 instead of the expected "test2" and I can't for the life of it seem to figure out what is going wrong 
    
    EDIT: Scrap that out, I figured it out (seems that Construct refuses to load the array if I use one bracket instead of two)
  • I do, however, have another question: Does C2 cary a function to convert JSON to a supported format?

  • What do you mean by "supported format" ?

    Something that would format your json if not formated right in order to load an array from it ? no.

    A way to get data from a given JSON without loading it in an object ? yes : javascript. The system object has "execJS" action, that will execute a JS string and return the return value (if used inline). In this context, if X is your JSON string, you can execJS("var a ="&X). This will set the window.a variable to the content of the JSON. You will then be able to access data from a using execJS again.

  • I got a function, I want to import this into C2 and parse a file into this, saving it into an array.

    Is there a way to:

    1. Import a whole javascript function

    2. Have an file select dialogue

    I already have an HTML file select page with a converter function that converts a JSON file with our datastructure into a file that C2 understands. This is running on qdekoster.nl/testing.html (can't post complete urls yet) In the source code of this page, the function is also visible.

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