语法
json.escape(text: string): string参数
| 名称 | 类型 | 描述 |
|---|---|---|
text | string | 操作使用的文本值。 |
返回值
| 名称 | 类型 | 描述 |
|---|---|---|
escaped | string | 转义的 JSON 字符串内容。 |
说明
对文本进行转义,以便它可以安全地出现在 JSON 字符串文字中。
使用 1 个参数调用: text。参数表会说明哪些值必填,哪些值只用于细化行为。
返回 escaped (string)。使用返回表区分成功值、nil 结果和可恢复错误。
示例
转义文本以在 JSON 字符串内使用。
local source = "line 1" .. string.char(10) .. "line 2"
local escaped = json.escape(source)
print(escaped)