class_jsonparseresult.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Properties
  13. ----------
  14. +---------------------------------------+------------------------------------------------------------------+
  15. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`error<class_JSONParseResult_property_error>` |
  16. +---------------------------------------+------------------------------------------------------------------+
  17. | :ref:`int<class_int>` | :ref:`error_line<class_JSONParseResult_property_error_line>` |
  18. +---------------------------------------+------------------------------------------------------------------+
  19. | :ref:`String<class_String>` | :ref:`error_string<class_JSONParseResult_property_error_string>` |
  20. +---------------------------------------+------------------------------------------------------------------+
  21. | :ref:`Variant<class_Variant>` | :ref:`result<class_JSONParseResult_property_result>` |
  22. +---------------------------------------+------------------------------------------------------------------+
  23. Description
  24. -----------
  25. 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``.
  26. Property Descriptions
  27. ---------------------
  28. .. _class_JSONParseResult_property_error:
  29. - :ref:`Error<enum_@GlobalScope_Error>` **error**
  30. +----------+------------------+
  31. | *Setter* | set_error(value) |
  32. +----------+------------------+
  33. | *Getter* | get_error() |
  34. +----------+------------------+
  35. The error type if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@GlobalScope>` ERR\_\* constants.
  36. .. _class_JSONParseResult_property_error_line:
  37. - :ref:`int<class_int>` **error_line**
  38. +----------+-----------------------+
  39. | *Setter* | set_error_line(value) |
  40. +----------+-----------------------+
  41. | *Getter* | get_error_line() |
  42. +----------+-----------------------+
  43. The line number where the error occurred if JSON source was not successfully parsed.
  44. .. _class_JSONParseResult_property_error_string:
  45. - :ref:`String<class_String>` **error_string**
  46. +----------+-------------------------+
  47. | *Setter* | set_error_string(value) |
  48. +----------+-------------------------+
  49. | *Getter* | get_error_string() |
  50. +----------+-------------------------+
  51. The error message if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@GlobalScope>` ERR\_\* constants.
  52. .. _class_JSONParseResult_property_result:
  53. - :ref:`Variant<class_Variant>` **result**
  54. +----------+-------------------+
  55. | *Setter* | set_result(value) |
  56. +----------+-------------------+
  57. | *Getter* | get_result() |
  58. +----------+-------------------+
  59. 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.
  60. *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.*
  61. 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:*
  62. ::
  63. var p = JSON.parse('["hello", "world", "!"]')
  64. if typeof(p.result) == TYPE_ARRAY:
  65. print(p.result[0]) # prints 'hello'
  66. else:
  67. print("unexpected results")