Files
godot-docs/classes/class_jsonparseresult.rst
2017-10-11 23:56:28 +02:00

97 lines
5.4 KiB
ReStructuredText

.. Generated automatically by doc/tools/makerst.py in Godot's source tree.
.. DO NOT EDIT THIS FILE, but the JSONParseResult.xml source instead.
.. The source is found in doc/classes or modules/<name>/doc_classes.
.. _class_JSONParseResult:
JSONParseResult
===============
**Inherits:** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
**Category:** Core
Brief Description
-----------------
Data class wrapper for decoded JSON.
Member Functions
----------------
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_error<class_JSONParseResult_get_error>` **(** **)** const |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_error_line<class_JSONParseResult_get_error_line>` **(** **)** const |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| :ref:`String<class_string>` | :ref:`get_error_string<class_JSONParseResult_get_error_string>` **(** **)** const |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| :ref:`Variant<class_variant>` | :ref:`get_result<class_JSONParseResult_get_result>` **(** **)** const |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_error<class_JSONParseResult_set_error>` **(** :ref:`int<class_int>` error **)** |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_error_line<class_JSONParseResult_set_error_line>` **(** :ref:`int<class_int>` error_line **)** |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_error_string<class_JSONParseResult_set_error_string>` **(** :ref:`String<class_string>` error_string **)** |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_result<class_JSONParseResult_set_result>` **(** :ref:`Variant<class_variant>` result **)** |
+--------------------------------+------------------------------------------------------------------------------------------------------------------------+
Member Variables
----------------
- :ref:`int<class_int>` **error** - The error type if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants.
- :ref:`int<class_int>` **error_line** - The line number where the error occurred if JSON source was not successfully parsed.
- :ref:`String<class_string>` **error_string** - The error message if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants.
- :ref:`Variant<class_variant>` **result** - 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]
Description
-----------
Returned by :ref:`JSON.parse<class_JSON_parse>`, :ref:`JSONParseResult<class_jsonparseresult>` contains decoded JSON or error information if JSON source not successfully parsed. You can check if JSON source was successfully parsed with ``if json_result.error == 0``.
Member Function Description
---------------------------
.. _class_JSONParseResult_get_error:
- :ref:`int<class_int>` **get_error** **(** **)** const
.. _class_JSONParseResult_get_error_line:
- :ref:`int<class_int>` **get_error_line** **(** **)** const
.. _class_JSONParseResult_get_error_string:
- :ref:`String<class_string>` **get_error_string** **(** **)** const
.. _class_JSONParseResult_get_result:
- :ref:`Variant<class_variant>` **get_result** **(** **)** const
.. _class_JSONParseResult_set_error:
- void **set_error** **(** :ref:`int<class_int>` error **)**
.. _class_JSONParseResult_set_error_line:
- void **set_error_line** **(** :ref:`int<class_int>` error_line **)**
.. _class_JSONParseResult_set_error_string:
- void **set_error_string** **(** :ref:`String<class_string>` error_string **)**
.. _class_JSONParseResult_set_result:
- void **set_result** **(** :ref:`Variant<class_variant>` result **)**