Why can C2 not read a JSON files it itself makes? (Solved)

0 favourites
  • 12 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • Any one who is familiar with my post history knows that I am not too knowledgeable about JSON/AJAX. This is a more general question and hope to help not only myself but others who maybe have noticed this strange occurrence.

    I am trying to Save/Load a Array using JSON with a bit of help from Rex's CSV2Array. But since I am not too skilled with writing JSON strings I have kind of found a lazy mans way to get them. I put the CSV into the array like

    "Red,Blue,Blue

    Red,Red,Blue

    Green,Green,Blue"

    I then have a small board that I assign colored animations to depending on running a for each XYvalue loop. That all works great. The board changes colors just as I expect. However now I use my trick to set the text of a text object to be the JSON of the array. Then from within C2Debug I copy n past that sting to a notepad file and save it to my project files.

    Here is where my problem starts.

    the JSON looks much like

    {"c2array":true,"size":[3,3,1],"data":[ [ ["Red"],["Blue"],["Blue"] ],[ ["Red"],["Red"],["Blue"] ],[ ["Green"],["Green"],["Blue"] ] ] }

    However when I put the vary same JSON sting back into C2 it gives me all kinds of syntax errors. Why? It is literally the exact same JSON that C2 spit out and directly plugged back in. Anyone know what I may be doing wrong?

  • Are you using project files or inputing the string as a litteral ? If it's a litteral string, you need to escape double quotes with another double quotes. Otherwise it might be some kind of encoding problem...

  • Are you using project files or inputing the string as a litteral ? If it's a litteral string, you need to escape double quotes with another double quotes. Otherwise it might be some kind of encoding problem...

    "{""c2array"":true,""size"":[3,3,1],""data"":[ [ [""Red""],[""Blue""],[""Blue""] ],[ [""Red""],[""Red""],[""Blue""] ],[ [""Green""],[""Green""],[""Blue""] ] ] }"

    Haveing done that I now It will work if I put it directly into Load From JSON but once Ajax get involved it will not work. I check the AJAX tool in debug and it will put the text exactaly as is from the project folder. So I really dont know.

    edit - here is a demo of what I am trying to do. Needs Rex-Board-Core plugin

    https://www.dropbox.com/s/ggoezgt1gdf8ipr/TileMapDemo.capx?dl=0

  • It's a stretch but try saving your text file in UTF-8 encoding... we never know ! Also, make sure to remove any trailing of leading characters from the file.

  • It's a stretch but try saving your text file in UTF-8 encoding... we never know ! Also, make sure to remove any trailing of leading characters from the file.

    Just resaved the project file for UTF-8 and tried both escaped and non escaped to no success

  • {"c2array":true,"size":[3,3,1],"data":[[["Red"],["Blue"],["Blue"]],[["Red"],["Red"],["Blue"]],[["Green"],["Green"],["Blue"]]]}

    Just made a new project and everything is loading with no problems into Ajax and then Array. Nothing was changed or edited, just saved as file.json.

  • {"c2array":true,"size":[3,3,1],"data":[[["Red"],["Blue"],["Blue"]],[["Red"],["Red"],["Blue"]],[["Green"],["Green"],["Blue"]]]}[/code:1fb7lqaj]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Indeed korbaach you are correct as it was I was trying to load json string immediately after calling it with out the n completed step, thank you.

  • If you had posted a capx, we would have seen it immediately. Just sayin'

  • If you had posted a capx, we would have seen it immediately. Just sayin'

    Third post my friend

    It was a edit in about 15min after the original post so it could have been easy to miss.

  • Oh yeah, I think I actually saw it, but since I did not have the required plugin, it failed to open. I was at work, and already had spent to much time goofing around with Construct so I kept it for later then forgot all about it... D:

  • Oh yeah, I think I actually saw it, but since I did not have the required plugin, it failed to open. I was at work, and already had spent to much time goofing around with Construct so I kept it for later then forgot all about it... D:

    Dont worry about it lol it's all good

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