09a905ca80
Fixes #34541 Renamed MAX_DIGITS to MAX_DECIMALS, since it only changes the amount of digits after the decimal point. Increased MAX_DECIMALS to 32, and made String::num use MAX_DECIMALS consistently. If -1 is passed as decimal precision to String::num, it now gets changed to the correct precision based on the number's magnitude, instead of using printf default(which is 6) String::num_real also calculates the correct precision now. Also made the types used in floating-point math more consistent in a few places.
63 lines
2.3 KiB
XML
63 lines
2.3 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<class name="JSON" inherits="Object" version="4.0">
|
|
<brief_description>
|
|
Helper class for parsing JSON data.
|
|
</brief_description>
|
|
<description>
|
|
Helper class for parsing JSON data. For usage example and other important hints, see [JSONParseResult].
|
|
</description>
|
|
<tutorials>
|
|
</tutorials>
|
|
<methods>
|
|
<method name="parse">
|
|
<return type="JSONParseResult">
|
|
</return>
|
|
<argument index="0" name="json" type="String">
|
|
</argument>
|
|
<description>
|
|
Parses a JSON-encoded string and returns a [JSONParseResult] containing the result.
|
|
</description>
|
|
</method>
|
|
<method name="print">
|
|
<return type="String">
|
|
</return>
|
|
<argument index="0" name="value" type="Variant">
|
|
</argument>
|
|
<argument index="1" name="indent" type="String" default="""">
|
|
</argument>
|
|
<argument index="2" name="sort_keys" type="bool" default="false">
|
|
</argument>
|
|
<argument index="3" name="full_precision" type="bool" default="false">
|
|
</argument>
|
|
<description>
|
|
Converts a [Variant] var to JSON text and returns the result. Useful for serializing data to store or send over the network.
|
|
[b]Note:[/b] The JSON specification does not define integer or float types, but only a [i]number[/i] type. Therefore, converting a Variant to JSON text will convert all numerical values to [float] types.
|
|
[b]Note:[/b] If [code]full_precision[/code] is true, when printing floats, the unreliable digits are printed in addition to the reliable digits to guarantee exact decoding.
|
|
Use [code]indent[/code] parameter to pretty print the output.
|
|
[b]Example output:[/b]
|
|
[codeblock]
|
|
## JSON.print(my_dictionary)
|
|
{"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]}
|
|
|
|
## JSON.print(my_dictionary, "\t")
|
|
{
|
|
"name": "my_dictionary",
|
|
"version": "1.0.0",
|
|
"entities": [
|
|
{
|
|
"name": "entity_0",
|
|
"value": "value_0"
|
|
},
|
|
{
|
|
"name": "entity_1",
|
|
"value": "value_1"
|
|
}
|
|
]
|
|
}
|
|
[/codeblock]
|
|
</description>
|
|
</method>
|
|
</methods>
|
|
<constants>
|
|
</constants>
|
|
</class>
|