Error when working with JSON

I've been uploading json files unto a webserver and had no problem with them on game maker... for some reason I now keep getting this error with a new project I have started :

json_decode argument 1 incorrect type (undefined) expecting a Number (YYGR)



Create Event
http_get("website.json")
question = ""



HTTP Event

// Get the answer
json = async_load[? "result"];

//Convert Json to ds_map
map = json_decode(json);
if (map == -1)
{
show_message("Invalid")
exit;
}

if (ds_map_exists(map, "question"))
{
question = map[? "quesiont"];

}


When executing the program I get
json_decode argument 1 incorrect type (undefined) expecting a Number (YYGR)
I've never had this problem before working with JSON files
 
H

Homunculus

Guest
You are using http_get the wrong way. http_get returns the id of the http request, that you have to store in a variable.

In the Async event you have to check that the data you are getting is in fact related to that call, by comparing the id with async_load[? "id"];

Afterwards you can't just get the result by using json = async_load[? "result"]; , you have to check if the request returned an error, if it's still downloading the data, or if it's finished (and you can actually get the result).
You do that by checking if async_load[? "status"]; is less than 0 (error), exactly 0 (downloading), 1 (finished).

The manual entry for http_get does provide an example of all of the above.
 
Top