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

Get help using Construct 2

Post » Thu Jul 30, 2015 7:28 pm

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? :shock:
Last edited by CrazyVulcan on Fri Jul 31, 2015 5:58 pm, edited 1 time in total.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Thu Jul 30, 2015 8:12 pm

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...
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Thu Jul 30, 2015 8:49 pm

Magistross wrote: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
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Thu Jul 30, 2015 9:07 pm

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.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Thu Jul 30, 2015 9:16 pm

Magistross wrote: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
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Thu Jul 30, 2015 9:30 pm

{"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.
ImageImageImageImage
B
157
S
65
G
41
Posts: 2,594
Reputation: 34,748

Post » Thu Jul 30, 2015 9:42 pm

Image
Code: Select all
{"c2array":true,"size":[3,3,1],"data":[[["Red"],["Blue"],["Blue"]],[["Red"],["Red"],["Blue"]],[["Green"],["Green"],["Blue"]]]}
Image
B
64
S
23
G
7
Posts: 1,483
Reputation: 10,827

Post » Fri Jul 31, 2015 5:57 pm

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.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Fri Jul 31, 2015 6:16 pm

If you had posted a capx, we would have seen it immediately. Just sayin' ;)
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Fri Jul 31, 2015 6:33 pm

Magistross wrote: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.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Next

Return to How do I....?

Who is online

Users browsing this forum: sublimate and 2 guests