class_jsonparseresult.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the JSONParseResult.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_JSONParseResult:
  5. JSONParseResult
  6. ===============
  7. **Inherits:** :ref:`Reference<class_reference>` **<** :ref:`Object<class_object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. Data class wrapper for decoded JSON.
  12. Member Functions
  13. ----------------
  14. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`int<class_int>` | :ref:`get_error<class_JSONParseResult_get_error>` **(** **)** const |
  16. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`int<class_int>` | :ref:`get_error_line<class_JSONParseResult_get_error_line>` **(** **)** const |
  18. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`String<class_string>` | :ref:`get_error_string<class_JSONParseResult_get_error_string>` **(** **)** const |
  20. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`Variant<class_variant>` | :ref:`get_result<class_JSONParseResult_get_result>` **(** **)** const |
  22. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  23. | void | :ref:`set_error<class_JSONParseResult_set_error>` **(** :ref:`int<class_int>` error **)** |
  24. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  25. | void | :ref:`set_error_line<class_JSONParseResult_set_error_line>` **(** :ref:`int<class_int>` error_line **)** |
  26. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`set_error_string<class_JSONParseResult_set_error_string>` **(** :ref:`String<class_string>` error_string **)** |
  28. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`set_result<class_JSONParseResult_set_result>` **(** :ref:`Variant<class_variant>` result **)** |
  30. +--------------------------------+------------------------------------------------------------------------------------------------------------------------+
  31. Member Variables
  32. ----------------
  33. - :ref:`int<class_int>` **error** - The error type if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants.
  34. - :ref:`int<class_int>` **error_line** - The line number where the error occurred if JSON source was not successfully parsed.
  35. - :ref:`String<class_string>` **error_string** - The error message if JSON source was not successfully parsed. See [@Global Scope]ERR_* constants.
  36. - :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.
  37. [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]
  38. [codeblock]
  39. p = JSON.parse('["hello", "world", "!"]')
  40. if typeof(p) == TYPE_ARRAY:
  41. print(p[0]) # prints 'hello'
  42. else:
  43. print("unexpected results")
  44. [/codeblock]
  45. Description
  46. -----------
  47. 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``.
  48. Member Function Description
  49. ---------------------------
  50. .. _class_JSONParseResult_get_error:
  51. - :ref:`int<class_int>` **get_error** **(** **)** const
  52. .. _class_JSONParseResult_get_error_line:
  53. - :ref:`int<class_int>` **get_error_line** **(** **)** const
  54. .. _class_JSONParseResult_get_error_string:
  55. - :ref:`String<class_string>` **get_error_string** **(** **)** const
  56. .. _class_JSONParseResult_get_result:
  57. - :ref:`Variant<class_variant>` **get_result** **(** **)** const
  58. .. _class_JSONParseResult_set_error:
  59. - void **set_error** **(** :ref:`int<class_int>` error **)**
  60. .. _class_JSONParseResult_set_error_line:
  61. - void **set_error_line** **(** :ref:`int<class_int>` error_line **)**
  62. .. _class_JSONParseResult_set_error_string:
  63. - void **set_error_string** **(** :ref:`String<class_string>` error_string **)**
  64. .. _class_JSONParseResult_set_result:
  65. - void **set_result** **(** :ref:`Variant<class_variant>` result **)**