class_jsonparseresult.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the JSONParseResult.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_JSONParseResult:
  6. JSONParseResult
  7. ===============
  8. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. Data class wrapper for decoded JSON.
  10. Description
  11. -----------
  12. 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``.
  13. Properties
  14. ----------
  15. +---------------------------------------+------------------------------------------------------------------+--------+
  16. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`error<class_JSONParseResult_property_error>` | |
  17. +---------------------------------------+------------------------------------------------------------------+--------+
  18. | :ref:`int<class_int>` | :ref:`error_line<class_JSONParseResult_property_error_line>` | ``-1`` |
  19. +---------------------------------------+------------------------------------------------------------------+--------+
  20. | :ref:`String<class_String>` | :ref:`error_string<class_JSONParseResult_property_error_string>` | ``""`` |
  21. +---------------------------------------+------------------------------------------------------------------+--------+
  22. | :ref:`Variant<class_Variant>` | :ref:`result<class_JSONParseResult_property_result>` | |
  23. +---------------------------------------+------------------------------------------------------------------+--------+
  24. Property Descriptions
  25. ---------------------
  26. .. _class_JSONParseResult_property_error:
  27. - :ref:`Error<enum_@GlobalScope_Error>` **error**
  28. +----------+------------------+
  29. | *Setter* | set_error(value) |
  30. +----------+------------------+
  31. | *Getter* | get_error() |
  32. +----------+------------------+
  33. The error type if the JSON source was not successfully parsed. See the :ref:`Error<enum_@GlobalScope_Error>` constants.
  34. ----
  35. .. _class_JSONParseResult_property_error_line:
  36. - :ref:`int<class_int>` **error_line**
  37. +-----------+-----------------------+
  38. | *Default* | ``-1`` |
  39. +-----------+-----------------------+
  40. | *Setter* | set_error_line(value) |
  41. +-----------+-----------------------+
  42. | *Getter* | get_error_line() |
  43. +-----------+-----------------------+
  44. The line number where the error occurred if the JSON source was not successfully parsed.
  45. ----
  46. .. _class_JSONParseResult_property_error_string:
  47. - :ref:`String<class_String>` **error_string**
  48. +-----------+-------------------------+
  49. | *Default* | ``""`` |
  50. +-----------+-------------------------+
  51. | *Setter* | set_error_string(value) |
  52. +-----------+-------------------------+
  53. | *Getter* | get_error_string() |
  54. +-----------+-------------------------+
  55. The error message if the JSON source was not successfully parsed. See the :ref:`Error<enum_@GlobalScope_Error>` constants.
  56. ----
  57. .. _class_JSONParseResult_property_result:
  58. - :ref:`Variant<class_Variant>` **result**
  59. +----------+-------------------+
  60. | *Setter* | set_result(value) |
  61. +----------+-------------------+
  62. | *Getter* | get_result() |
  63. +----------+-------------------+
  64. 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.
  65. **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.
  66. **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:
  67. ::
  68. var p = JSON.parse('["hello", "world", "!"]')
  69. if typeof(p.result) == TYPE_ARRAY:
  70. print(p.result[0]) # Prints "hello"
  71. else:
  72. push_error("Unexpected results.")
  73. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  74. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  75. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`