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.
If the JSON to be decoded requires a hierarchy of lists and maps within the central DS map, these are decoded too and also created for you, using the following rules (note that these rules apply to the top-level structure only): With this function, you can decode a piece of JSON and convert it into a DS Map, ready for use in GameMaker. An ordered list of values, called a DS List in GameMaker but this can also be called an "array" or "sequence".A collection of name/value pairs, called a DS Map in GameMaker but also known as a "dictionary" or "object".JSON (JavaScript Object Notation) is a lightweight data-interchange format which is easy for to read and write, for both people and machines. Json_decode IMPORTANT! This function - while still valid - has been superseded by the function json_parse(), and we recommend that you only use this function for legacy support.