#Json decode code#
The above code will decode a JSON string and parse it to generate a global array.JS Tutorial JS HOME JS Introduction JS Where To JS Output JS Statements JS Syntax JS Comments JS Variables JS Let JS Const JS Operators JS Arithmetic JS Assignment JS Data Types JS Functions JS Objects JS Events JS Strings JS String Methods JS String Search JS String Templates JS Numbers JS Number Methods JS Arrays JS Array Methods JS Array Sort JS Array Iteration JS Array Const JS Dates JS Date Formats JS Date Get Methods JS Date Set Methods JS Math JS Random JS Booleans JS Comparisons JS If Else JS Switch JS Loop For JS Loop For In JS Loop For Of JS Loop While JS Break JS Iterables JS Sets JS Maps JS Typeof JS Type Conversion JS Bitwise JS RegExp JS Errors JS Scope JS Hoisting JS Strict Mode JS this Keyword JS Arrow Function JS Classes JS Modules JS JSON JS Debugging JS Style Guide JS Best Practices JS Mistakes JS Performance JS Reserved Words Global.Name = ds_map_find_value(map, "name") Var list = ds_map_find_value(resultMap, "default") įor (var n = 0 n < ds_list_size(list) n++ ) Var resultMap = json_decode(requestResult) The JSON format string that you are passing to the function for decoding IMPORTANT: You cannot have 64bit numbers in your JSON, as they will not work correctly due them not being handled by the JSON format. NOTE: This function allows you to load JSON files with a maximum nesting limit of 128. NOTE: GameMaker creates the necessary DS maps and lists from the JSON, and for cleaning up you only need to delete the top level map or list and GameMaker will automatically delete from memory all the maps and lists underneath. Normally you would know what keys the JSON decodes to, but if not then you can use the ds_map_size(), ds_map_find_first() and ds_map_find_next() functions to parse the map and get the necessary information.
NOTE: If you wrote GameMaker arrays into the top level, or as the contents of a DS map or DS list, these will be decoded as DS lists, not arrays.
Internal lists decode directly to DS map without being enclosed in a DS map. NOTE: When decoding JSON 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.
JSON is an object - returns a DS map that has the object entries in it.JSON is an array of objects or values - returns a DS map with a single entry "default" that is a DS list of the objects or values.