class_jsonparseresult.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Data class wrapper for decoded JSON.
  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>` |
  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. Description
  25. -----------
  26. Returned by :ref:`JSON.parse<class_JSON_method_parse>`, ``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 == OK``.
  27. Property Descriptions
  28. ---------------------
  29. .. _class_JSONParseResult_property_error:
  30. - :ref:`Error<enum_@GlobalScope_Error>` **error**
  31. +----------+------------------+
  32. | *Setter* | set_error(value) |
  33. +----------+------------------+
  34. | *Getter* | get_error() |
  35. +----------+------------------+
  36. The error type if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@GlobalScope>` ERR\_\* constants.
  37. ----
  38. .. _class_JSONParseResult_property_error_line:
  39. - :ref:`int<class_int>` **error_line**
  40. +----------+-----------------------+
  41. | *Setter* | set_error_line(value) |
  42. +----------+-----------------------+
  43. | *Getter* | get_error_line() |
  44. +----------+-----------------------+
  45. The line number where the error occurred if JSON source was not successfully parsed.
  46. ----
  47. .. _class_JSONParseResult_property_error_string:
  48. - :ref:`String<class_String>` **error_string**
  49. +----------+-------------------------+
  50. | *Setter* | set_error_string(value) |
  51. +----------+-------------------------+
  52. | *Getter* | get_error_string() |
  53. +----------+-------------------------+
  54. The error message if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@GlobalScope>` ERR\_\* constants.
  55. ----
  56. .. _class_JSONParseResult_property_result:
  57. - :ref:`Variant<class_Variant>` **result**
  58. +----------+-------------------+
  59. | *Setter* | set_result(value) |
  60. +----------+-------------------+
  61. | *Getter* | get_result() |
  62. +----------+-------------------+
  63. A :ref:`Variant<class_Variant>` containing the parsed JSON. Use typeof() to check if it is what you expect. For example, if JSON source starts with curly braces (``{}``) a :ref:`Dictionary<class_Dictionary>` will be returned, if JSON source starts with braces (``[]``) an :ref:`Array<class_Array>` will be returned.
  64. *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.*
  65. Note that 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:*
  66. ::
  67. var p = JSON.parse('["hello", "world", "!"]')
  68. if typeof(p.result) == TYPE_ARRAY:
  69. print(p.result[0]) # prints 'hello'
  70. else:
  71. print("unexpected results")