Pfap
Member
Does anybody have any input on decoding the below JSON into gamemaker maps and lists?
I had the input being received fine until, I added the array under the "avatar" key.
Here is the JSON:
And here is the code and how I think it should work... the manual is rather cryptic to me when it comes to nested lists. If I can't figure out how to parse nested lists I can always flatten it out, but it would be convenient to grab lists.
I am not entirely sure what the issue is and the console output is as expected.
Gamemaker console output for show_debug_message(response):
So, I have an array or list with 4 objects or maps.
How can I get at the internal lists under the "avatar" key?
Here is the note from the manual section on json_decode that I am having trouble deciphering:
I had the input being received fine until, I added the array under the "avatar" key.
Here is the JSON:
Code:
[{"friend":"e8553","wins":0,"level":0,"name":"srtht","avatar":[0,0,0,0,0,0,0,0,0,0,"srtht",89,1],"losses":0},{"friend":"d21fc","wins":0,"level":0,"name":"sfdgsg","avatar":[0,0,0,0,0,0,0,0,0,0,"sfdgsg",89,1],"losses":0},{"friend":"bb0ca","wins":0,"level":0,"name":"strhr","avatar":[0,0,0,0,0,0,0,0,0,0,"strhr",89,1],"losses":0},{"friend":"b90ac","wins":0,"level":0,"name":"sdfgsdf","avatar":[0,0,0,0,0,0,0,0,0,0,"sdfgsdf",89,1],"losses":0}]
Code:
var response = ds_map_find_value(async_load, "result");
show_debug_message(response);
var working_data = json_decode(response);
show_debug_message(working_data);
//before adding the internal lists this would return a list with the maps
var list = ds_map_find_first(working_data);
show_debug_message(list);//default
//size was the amount of internal maps or objects
var size = ds_list_size(list);
show_debug_message(size);
//repeat for each object in the JSON
var pos = 0;
repeat(size){
var currentMap = ds_list_find_value(list,list_pos);
inst.friend = ds_map_find_value(currentMap,"friend");
inst.name = ds_map_find_value(currentMap,"name");
inst.wins = ds_map_find_value(currentMap,"wins");
inst.levels = ds_map_find_value(currentMap,"level");
inst.losses = ds_map_find_value(currentMap,"losses");
//I am expecting a list here
var avatar_list = ds_map_find_value(currentMap,"avatar");
pos += 1;
}
I am not entirely sure what the issue is and the console output is as expected.
Gamemaker console output for show_debug_message(response):
Code:
[{"friend":"e8553","wins":0,"level":0,"name":"srtht","avatar":[0,0,0,0,0,0,0,0,0,0,"srtht",89,1],"losses":0},{"friend":"d21fc","wins":0,"level":0,"name":"sfdgsg","avatar":[0,0,0,0,0,0,0,0,0,0,"sfdgsg",89,1],"losses":0},{"friend":"bb0ca","wins":0,"level":0,"name":"strhr","avatar":[0,0,0,0,0,0,0,0,0,0,"strhr",89,1],"losses":0},{"friend":"b90ac","wins":0,"level":0,"name":"sdfgsdf","avatar":[0,0,0,0,0,0,0,0,0,0,"sdfgsdf",89,1],"losses":0}]
How can I get at the internal lists under the "avatar" key?
Here is the note from the manual section on json_decode that I am having trouble deciphering:
In my code I am trying to access the list from within the maps, but the above note states that internal lists decode without being enclosed in a map? If so, how can I access them? Or will I just need to restructure how I send out my data?NOTE: When decoding arrays, there is a map with the key "default" ONLY when an array is the top level structure, and ONLY for that top-level array. Internal lists decode directly to ds_lists without being enclosed in a ds_map.