JSON 模块

函数名称:sz.json.encode、sz.json.decode

函数功能:json 串编码、解码

函数用例

local sz = require("sz")--使用 sz 库前必须插入这一句
local json = sz.json--使用 JSON 模块前必须插入这一句
local tb = {
    ["我"] = "苏泽",
    ["爱"] = "娜娜",
    meme = {
        isArray = true,
        1,0,0,4,6,9,5,1,0,0,
    },
    nullvalue = null,
}
local jsonstring = json.encode(tb);
dialog(jsonstring, 0);

local tmp = json.decode(jsonstring);
dialog(tmp.meme[5], 0);
dialog(tostring(tmp.nullvalue), 0);
--unicode 转 utf8
local sz = require "sz"
local tmp = sz.json.totable([[{"toUTF8":"\u6211\u7231\u5a1c\u5a1c"}]])
dialog(tmp["toUTF8"],0)

注意事项

  • 在 JSON 格式的 ShowUI 时会用到 JSON 模块
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""