summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2022-04-25 17:23:39 +0200
committerkobewi <kobewi4e@gmail.com>2022-08-16 14:29:38 +0200
commit5947f688fbdc290428afacfaa75b327f556a549d (patch)
treedfb5006fb956ff98cd731c75eb789796889b9edb /doc
parentd5d22ab035a611a567f73a2ee2d61a81c99c61b5 (diff)
Make JSON methods static
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/JSON.xml17
1 files changed, 14 insertions, 3 deletions
diff --git a/doc/classes/JSON.xml b/doc/classes/JSON.xml
index 49ebb55a52..46e46cc164 100644
--- a/doc/classes/JSON.xml
+++ b/doc/classes/JSON.xml
@@ -10,8 +10,7 @@
[b]Example[/b]
[codeblock]
var data_to_send = ["a", "b", "c"]
- var json = JSON.new()
- var json_string = json.stringify(data_to_send)
+ var json_string = JSON.stringify(data_to_send)
# Save data
# ...
# Retrieve data
@@ -25,6 +24,10 @@
else:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
[/codeblock]
+ Alternatively, you can parse string using the static [method parse_string] method, but it doesn't allow to handle errors.
+ [codeblock]
+ var data = JSON.parse_string(json_string) # Returns null if parsing failed.
+ [/codeblock]
</description>
<tutorials>
</tutorials>
@@ -54,9 +57,17 @@
<description>
Attempts to parse the [param json_string] provided.
Returns an [enum Error]. If the parse was successful, it returns [code]OK[/code] and the result can be retrieved using [method get_data]. If unsuccessful, use [method get_error_line] and [method get_error_message] for identifying the source of the failure.
+ Non-static variant of [method parse_string], if you want custom error handling.
+ </description>
+ </method>
+ <method name="parse_string" qualifiers="static">
+ <return type="Variant" />
+ <param index="0" name="json_string" type="String" />
+ <description>
+ Attempts to parse the [param json_string] provided and returns the parsed data. Returns [code]null[/code] if parse failed.
</description>
</method>
- <method name="stringify">
+ <method name="stringify" qualifiers="static">
<return type="String" />
<param index="0" name="data" type="Variant" />
<param index="1" name="indent" type="String" default="&quot;&quot;" />