JSON
JSON 库。
🗿Static Class
This is a Static Class. Access it's methods directly with
.. It's not possible to spawn new instances.🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
🎒 示例
(JSON.stringify) Stringifies a Lua table
local encoded_value = JSON.stringify({ 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" })
-- Outputs "[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]"
(JSON.parse) Parses a JSON string into a Lua table
local decoded_value = JSON.parse('[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]')
-- Outputs "the table { 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" }"
备注
请注意,自定义类(例如 Vehicle、Character、Prop…… 等等)或函数不支持字符串化,将被置空。
结构体(例如 Vector、Rotator、Color…… 等等)均受支持,并将被正确解析/字符串化!
🗿 静态函数
stringify
返回一个表示以 JSON 编码的值的字符串
local ret = JSON.stringify(value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| table | value | Required parameter | 将要转换为 JSON 的表 |
Returns
| Type | Description |
|---|---|
| string | JSON 格式的表 |
JSON.stringify Examples
Stringifies a Lua table
local encoded_value = JSON.stringify({ 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" })
-- Outputs "[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]"
parse
返回一个表示解码后的 JSON 字符串的值
local ret = JSON.parse(value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | value | Required parameter | 将要转换为表的 JSON |
Returns
| Type | Description |
|---|---|
| any | 转换为表的 JSON |
JSON.parse Examples
Parses a JSON string into a Lua table
local decoded_value = JSON.parse('[1,2,3,{"x":10,"y":"Vector(1.0, 2.0, 3.0)"},"he"]')
-- Outputs "the table { 1, 2, 3, { x = 10, y = Vector(1, 2, 3) }, "he" }"