SOLVED JSON read help

danastock

Member
Hello all,

I hope you are well.

I am trying running an API into my game, but I have run into an issue with game maker where it doesn't want to read numbered folders. Can anyone shed light into whether I am doing something wrong, or is this a GM limitation? See below reference.

Thanks

Screen Shot 2020-07-31 at 12.06.32 pm.png


var list = ds_map_find_value(resultMap, "eventsData");
var list2 = ds_map_find_value(list,"0");
global.hist_div_price_00 = ds_map_find_value(list2, "amount");
 
Last edited:

Nidoking

Member
The picture shows the number 0 (zero), while your code shows the string "0", which is not the number 0. Maybe you should try changing one or the other.
 

danastock

Member
The picture shows the number 0 (zero), while your code shows the string "0", which is not the number 0. Maybe you should try changing one or the other.
Thanks for your reply,

I have tried putting it as a number, but I have the same issue.

I have tried all of the below
var list2 = ds_map_find_value(list,0);
var list2 = ds_map_find_value(list,"0");
var list2 = ds_map_find_value(list,[0]);

Its sounding like a limitation within Game Maker?

Thanks
 
It looks to me like "eventsData" holds a list, not a map, therefore the function call should be a ds_list function not a ds_map function:
Code:
var list = ds_map_find_value(resultMap, "eventsData"); // List now holds a ds_list, not a ds_map
var list2 = ds_list_find_value(list,0); // Naming this list2 is bad practice, as it is actually a map
global.hist_div_price_00 = ds_map_find_value(list2, "amount");
There's no limitation in GMS in regards to JSON notation, at least in this respect, people use it every day. The limitation is in you understanding what structures are stored where within your JSON file.
 

danastock

Member
It looks to me like "eventsData" holds a list, not a map, therefore the function call should be a ds_list function not a ds_map function:
Code:
var list = ds_map_find_value(resultMap, "eventsData"); // List now holds a ds_list, not a ds_map
var list2 = ds_list_find_value(list,0); // Naming this list2 is bad practice, as it is actually a map
global.hist_div_price_00 = ds_map_find_value(list2, "amount");
There's no limitation in GMS in regards to JSON notation, at least in this respect, people use it every day. The limitation is in you understanding what structures are stored where within your JSON file.
Thanks, that helps alot!
 
Top