class_jsonparseresult.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/JSONParseResult.xml.
  6. .. _class_JSONParseResult:
  7. JSONParseResult
  8. ===============
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Data class wrapper for decoded JSON.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Returned by :ref:`JSON.parse<class_JSON_method_parse>`, **JSONParseResult** contains the decoded JSON or error information if the JSON source wasn't successfully parsed. You can check if the JSON source was successfully parsed with ``if json_result.error == OK``.
  15. .. rst-class:: classref-reftable-group
  16. Properties
  17. ----------
  18. .. table::
  19. :widths: auto
  20. +---------------------------------------+------------------------------------------------------------------+--------+
  21. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`error<class_JSONParseResult_property_error>` | |
  22. +---------------------------------------+------------------------------------------------------------------+--------+
  23. | :ref:`int<class_int>` | :ref:`error_line<class_JSONParseResult_property_error_line>` | ``-1`` |
  24. +---------------------------------------+------------------------------------------------------------------+--------+
  25. | :ref:`String<class_String>` | :ref:`error_string<class_JSONParseResult_property_error_string>` | ``""`` |
  26. +---------------------------------------+------------------------------------------------------------------+--------+
  27. | :ref:`Variant<class_Variant>` | :ref:`result<class_JSONParseResult_property_result>` | |
  28. +---------------------------------------+------------------------------------------------------------------+--------+
  29. .. rst-class:: classref-section-separator
  30. ----
  31. .. rst-class:: classref-descriptions-group
  32. Property Descriptions
  33. ---------------------
  34. .. _class_JSONParseResult_property_error:
  35. .. rst-class:: classref-property
  36. :ref:`Error<enum_@GlobalScope_Error>` **error**
  37. .. rst-class:: classref-property-setget
  38. - void **set_error** **(** :ref:`Error<enum_@GlobalScope_Error>` value **)**
  39. - :ref:`Error<enum_@GlobalScope_Error>` **get_error** **(** **)**
  40. The error type if the JSON source was not successfully parsed. See the :ref:`Error<enum_@GlobalScope_Error>` constants.
  41. .. rst-class:: classref-item-separator
  42. ----
  43. .. _class_JSONParseResult_property_error_line:
  44. .. rst-class:: classref-property
  45. :ref:`int<class_int>` **error_line** = ``-1``
  46. .. rst-class:: classref-property-setget
  47. - void **set_error_line** **(** :ref:`int<class_int>` value **)**
  48. - :ref:`int<class_int>` **get_error_line** **(** **)**
  49. The line number where the error occurred if the JSON source was not successfully parsed.
  50. .. rst-class:: classref-item-separator
  51. ----
  52. .. _class_JSONParseResult_property_error_string:
  53. .. rst-class:: classref-property
  54. :ref:`String<class_String>` **error_string** = ``""``
  55. .. rst-class:: classref-property-setget
  56. - void **set_error_string** **(** :ref:`String<class_String>` value **)**
  57. - :ref:`String<class_String>` **get_error_string** **(** **)**
  58. The error message if the JSON source was not successfully parsed. See the :ref:`Error<enum_@GlobalScope_Error>` constants.
  59. .. rst-class:: classref-item-separator
  60. ----
  61. .. _class_JSONParseResult_property_result:
  62. .. rst-class:: classref-property
  63. :ref:`Variant<class_Variant>` **result**
  64. .. rst-class:: classref-property-setget
  65. - void **set_result** **(** :ref:`Variant<class_Variant>` value **)**
  66. - :ref:`Variant<class_Variant>` **get_result** **(** **)**
  67. A :ref:`Variant<class_Variant>` containing the parsed JSON. Use :ref:`@GDScript.typeof<class_@GDScript_method_typeof>` or the ``is`` keyword to check if it is what you expect. For example, if the JSON source starts with curly braces (``{}``), a :ref:`Dictionary<class_Dictionary>` will be returned. If the JSON source starts with brackets (``[]``), an :ref:`Array<class_Array>` will be returned.
  68. \ **Note:** 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 :ref:`float<class_float>` types.
  69. \ **Note:** JSON objects do not preserve key order like Godot dictionaries, thus, you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
  70. ::
  71. var p = JSON.parse('["hello", "world", "!"]')
  72. if typeof(p.result) == TYPE_ARRAY:
  73. print(p.result[0]) # Prints "hello"
  74. else:
  75. push_error("Unexpected results.")
  76. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  77. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  78. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  79. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`