跳至正文
版本:bleeding-edge 🩸

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" }"
备注

请注意,自定义类(例如 VehicleCharacterProp…… 等等)或函数不支持字符串化,将被置空。

结构体(例如 VectorRotatorColor…… 等等)均受支持,并将被正确解析/字符串化!

🗿 静态函数

ReturnsNameDescription
stringstringify返回一个表示以 JSON 编码的值的字符串
anyparse返回一个表示解码后的 JSON 字符串的值

stringify

返回一个表示以 JSON 编码的值的字符串
local ret = JSON.stringify(value)

Parameters

TypeParameterDefaultDescription
tablevalue Required parameter 将要转换为 JSON 的表

Returns

TypeDescription
stringJSON 格式的表
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

TypeParameterDefaultDescription
stringvalue Required parameter 将要转换为表的 JSON

Returns

TypeDescription
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" }"