This shows you the differences between two versions of the page.
— |
json_explode [2017/07/06 03:52] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Synopsis:====== | ||
+ | [[json_explode]](<<var>> <<json data>>) | ||
+ | |||
+ | ======Technical:====== | ||
+ | This function de-serialises a valid [[http://json.org/|JSON]] string into an assign variable structure with the provided name. | ||
+ | |||
+ | JSON object names are converted into valid assign variable names by replacing all non-alphanumeric characters with the underscore character. JSON string values are loaded as-is (up to any embedded Unicode NUL character); JSON numeric values are converted subject to [[set_floating_point_math]] and [[set_floating_point_precision]]; JSON true and false boolean values are converted to 1 and 0 respectively; and JSON null values are converted to an empty string. | ||
+ | |||
+ | If the function fails, the result variable is not modified and a descriptive error string is available from the [[json_error]] function. | ||
+ | |||
+ | ======Returns:====== | ||
+ | | 1 |The function succeeded.| | ||
+ | |<<empty>>|The function failed.| | ||
+ | |||
+ | ======Examples:====== | ||
+ | |||
+ | @ json = [ \ | ||
+ | { \ | ||
+ | "name": "Jack (\"Bee\") Nimble", \ | ||
+ | "format": { \ | ||
+ | "type": "rect", \ | ||
+ | "width": 1920, \ | ||
+ | "height": 1080, \ | ||
+ | "interlace": false, \ | ||
+ | "frame rate": 24 \ | ||
+ | } \ | ||
+ | }] | ||
+ | | ||
+ | if (json_explode(foo $json)) { | ||
+ | echo $foo[format][width] | ||
+ | } else { | ||
+ | echo JSON parse error: $json_error() | ||
+ | } | ||
+ | | ||
+ | ======See Also:====== | ||
+ | [[json_error]], [[json_implode]] |