From b8db909f48aead54b99bb91c331644d5dcd54626 Mon Sep 17 00:00:00 2001 From: Jerome67000 Date: Sun, 1 Oct 2017 01:42:56 +0200 Subject: [DOCS] Adds JSON and JSONParseResult doc --- doc/classes/JSON.xml | 4 ++++ doc/classes/JSONParseResult.xml | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml index a38b2f61cf..8bff140bb4 100644 --- a/doc/classes/JSON.xml +++ b/doc/classes/JSON.xml @@ -1,8 +1,10 @@ + Helper class for parsing JSON data. + Helper class for parsing JSON data. @@ -15,6 +17,7 @@ + Parses a JSON encoded string and returns a [JSONParseResult] containing the result. @@ -23,6 +26,7 @@ + Converts a Variant var to JSON text and returns the result. Useful for serializing data to store or send over the network. diff --git a/doc/classes/JSONParseResult.xml b/doc/classes/JSONParseResult.xml index 6aeb614508..86edaaf1e6 100644 --- a/doc/classes/JSONParseResult.xml +++ b/doc/classes/JSONParseResult.xml @@ -1,8 +1,10 @@ + Data class wrapper for decoded JSON. + Returned by [method JSON.parse], [JSONParseResult] contains decoded JSON or error information if JSON source not successfully parsed. You can check if JSON source was successfully parsed with [code]if json_result.error == 0[/code]. @@ -68,12 +70,24 @@ + The error type if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants. + The line number where the error occurred if JSON source was not successfully parsed. + The error message if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants. + A [Variant] containing the parsed JSON. Use typeof() to check if it is what you expect. For exemple, if JSON source starts with braces [code]{}[/code] a [Dictionary] will be returned, if JSON source starts with array braces [code][][/code] an [Array] will be returned. + [i]Be aware that the JSON specification does not define integer or float types, but only a number type. Therefore, parsing a JSON text will convert all numerical values to float types.[/i] + [codeblock] + p = JSON.parse('["hello", "world", "!"]') + if typeof(p) == TYPE_ARRAY: + print(p[0]) # prints 'hello' + else: + print("unexpected results") + [/codeblock] -- cgit v1.2.3