class_jsonparseresult.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 Variables
  13. ----------------
  14. .. _class_JSONParseResult_error:
  15. - :ref:`int<class_int>` **error** - The error type if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@globalscope>` ERR\_\* constants.
  16. .. _class_JSONParseResult_error_line:
  17. - :ref:`int<class_int>` **error_line** - The line number where the error occurred if JSON source was not successfully parsed.
  18. .. _class_JSONParseResult_error_string:
  19. - :ref:`String<class_string>` **error_string** - The error message if JSON source was not successfully parsed. See :ref:`@GlobalScope<class_@globalscope>` ERR\_\* constants.
  20. .. _class_JSONParseResult_result:
  21. - :ref:`Variant<class_variant>` **result** - 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.
  22. *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.*
  23. ::
  24. p = JSON.parse('["hello", "world", "!"]')
  25. if typeof(p) == TYPE_ARRAY:
  26. print(p[0]) # prints 'hello'
  27. else:
  28. print("unexpected results")
  29. Description
  30. -----------
  31. Returned by :ref:`JSON.parse<class_JSON_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 == 0``.