View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0026867||Runner||Functions||Public||2017-06-17 22:36||2019-01-30 15:47|
|Reporter||Eric Bunese||Assigned To||Alan Savage|
|Priority||Medium||Severity||C - General||Reproducibility||100%|
|Target Version||2.2.2||Fixed in Version||2.2.2|
|Summary||0026867: Functions: [GMS2] json_decode () doesn't strip BOM properly in http_get() results, breaks data parsing|
|Description||The ability to deal with json was a great addition to game maker. But when I attempted to include this possibility in my new GMS2.0 game, I noticed there are serious problems;|
-You have to escape double quotes, even when the string comes from a webserver/http request.
-Lists of objects are problematic.
I've created a thorough sample project which I am anexing to this report, which will be able to demonstrate the problems reported above.
Please read the object 'jsontest', the script 'escape_json' and test running the game on windows with both configurations; 'default' and 'FORCE_ERROR'.
The FORCE_ERROR configuration makes the script escape_json not escape the double quotes, causing a parse error in the json_decode function when the json has a list of objects. Because of this, json_decode returns -1. If the json is a simple array of strings, the behaviour is perfect, even when the configuration is set to FORCE_ERROR.
|Steps To Reproduce||Use variables to hold json and parse them, or load json from a server using an HTTP REQUEST, detect several problems when decoding and parsing the data structure|
|Tags||functions, HTTP, JSON, Runner|
|1.4 Found In||184.108.40.206|
|2.x Runtime Found In||220.127.116.11|
|2.x Runtime Verified In||18.104.22.1682|
jsontest.yyz (16,712 bytes)
I have found a workaround;
if you save async_load[?"result"] in a text file, and read the string from it again, the decoding will work just fine. Apparently, the problem comes from http get/posts
Any updates on this matter?
I've been using the workaround for a while now and it's not practical
Note that the json text examples in this project decode correctly without any escaping required - issue was only occurring for the json returned from the http_get, due to a byte order mark at the beginning of the returned string.
Fixed by stripping byte order mark if present in json_decode. (saving to a file and reloading also strips the BOM hence workaround mentioned below)