class_json.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 JSON.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_JSON:
  6. JSON
  7. ====
  8. **Inherits:** :ref:`Object<class_Object>`
  9. Helper class for parsing JSON data.
  10. Description
  11. -----------
  12. Helper class for parsing JSON data. For usage example and other important hints, see :ref:`JSONParseResult<class_JSONParseResult>`.
  13. Methods
  14. -------
  15. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`JSONParseResult<class_JSONParseResult>` | :ref:`parse<class_JSON_method_parse>` **(** :ref:`String<class_String>` json **)** |
  17. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :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 **)** |
  19. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. Method Descriptions
  21. -------------------
  22. .. _class_JSON_method_parse:
  23. - :ref:`JSONParseResult<class_JSONParseResult>` **parse** **(** :ref:`String<class_String>` json **)**
  24. Parses a JSON-encoded string and returns a :ref:`JSONParseResult<class_JSONParseResult>` containing the result.
  25. ----
  26. .. _class_JSON_method_print:
  27. - :ref:`String<class_String>` **print** **(** :ref:`Variant<class_Variant>` value, :ref:`String<class_String>` indent="", :ref:`bool<class_bool>` sort_keys=false **)**
  28. 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.
  29. **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.
  30. 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.
  31. **Example output:**
  32. ::
  33. ## JSON.print(my_dictionary)
  34. {"name":"my_dictionary","version":"1.0.0","entities":[{"name":"entity_0","value":"value_0"},{"name":"entity_1","value":"value_1"}]}
  35. ## JSON.print(my_dictionary, "\t")
  36. {
  37. "name": "my_dictionary",
  38. "version": "1.0.0",
  39. "entities": [
  40. {
  41. "name": "entity_0",
  42. "value": "value_0"
  43. },
  44. {
  45. "name": "entity_1",
  46. "value": "value_1"
  47. }
  48. ]
  49. }
  50. ## JSON.print(my_dictionary, "...")
  51. {
  52. ..."name": "my_dictionary",
  53. ..."version": "1.0.0",
  54. ..."entities": [
  55. ......{
  56. ........."name": "entity_0",
  57. ........."value": "value_0"
  58. ......},
  59. ......{
  60. ........."name": "entity_1",
  61. ........."value": "value_1"
  62. ......}
  63. ...]
  64. }
  65. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  66. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  67. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`