class_json.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/JSON.xml.
  6. .. _class_JSON:
  7. JSON
  8. ====
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Helper class for parsing JSON data.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Helper class for parsing JSON data. For usage example and other important hints, see :ref:`JSONParseResult<class_JSONParseResult>`.
  15. .. rst-class:: classref-reftable-group
  16. Methods
  17. -------
  18. .. table::
  19. :widths: auto
  20. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`JSONParseResult<class_JSONParseResult>` | :ref:`parse<class_JSON_method_parse>` **(** :ref:`String<class_String>` json **)** |
  22. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`String<class_String>` | :ref:`print<class_JSON_method_print>` **(** :ref:`Variant<class_Variant>` value, :ref:`String<class_String>` indent="", :ref:`bool<class_bool>` sort_keys=false **)** |
  24. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  25. .. rst-class:: classref-section-separator
  26. ----
  27. .. rst-class:: classref-descriptions-group
  28. Method Descriptions
  29. -------------------
  30. .. _class_JSON_method_parse:
  31. .. rst-class:: classref-method
  32. :ref:`JSONParseResult<class_JSONParseResult>` **parse** **(** :ref:`String<class_String>` json **)**
  33. Parses a JSON-encoded string and returns a :ref:`JSONParseResult<class_JSONParseResult>` containing the result.
  34. .. rst-class:: classref-item-separator
  35. ----
  36. .. _class_JSON_method_print:
  37. .. rst-class:: classref-method
  38. :ref:`String<class_String>` **print** **(** :ref:`Variant<class_Variant>` value, :ref:`String<class_String>` indent="", :ref:`bool<class_bool>` sort_keys=false **)**
  39. Converts a :ref:`Variant<class_Variant>` var to JSON text and returns the result. Useful for serializing data to store or send over the network.
  40. \ **Note:** The JSON specification does not define integer or float types, but only a *number* type. Therefore, converting a Variant to JSON text will convert all numerical values to :ref:`float<class_float>` types.
  41. The ``indent`` parameter controls if and how something is indented, the string used for this parameter will be used where there should be an indent in the output, even spaces like ``" "`` will work. ``\t`` and ``\n`` can also be used for a tab indent, or to make a newline for each indent respectively.
  42. \ **Example output:**\
  43. ::
  44. ## JSON.print(my_dictionary)
  45. {"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]}
  46. ## JSON.print(my_dictionary, "\t")
  47. {
  48. "name": "my_dictionary",
  49. "version": "1.0.0",
  50. "entities": [
  51. {
  52. "name": "entity_0",
  53. "value": "value_0"
  54. },
  55. {
  56. "name": "entity_1",
  57. "value": "value_1"
  58. }
  59. ]
  60. }
  61. ## JSON.print(my_dictionary, "...")
  62. {
  63. ..."name": "my_dictionary",
  64. ..."version": "1.0.0",
  65. ..."entities": [
  66. ......{
  67. ........."name": "entity_0",
  68. ........."value": "value_0"
  69. ......},
  70. ......{
  71. ........."name": "entity_1",
  72. ........."value": "value_1"
  73. ......}
  74. ...]
  75. }
  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.)`