#encoding/json
Xu 0.16.0 API
导入方式: #encoding/json
公开 API: 9 函数, 28 方法, 1 类型, 0 常量, 0 方法集
严格 JSON 与池化 Doc;as_int/as_f64 传播转换错误,旧数字访问器保留零值回退。
struct Doc
pub struct Doc {
pub kinds []int
pub texts []string
pub keys []string
pub firsts []int
pub nexts []int
pub lasts []int
pub root_idx int
pub err string
pub line int
pub raw string
pub i int
}
用途
承载 kinds、texts、keys、firsts、nexts 等属性的结构体。
公开字段
kinds []int- 字段([]int)
texts []string- 字段([]string)
keys []string- 字段([]string)
firsts []int- 字段([]int)
nexts []int- 字段([]int)
lasts []int- 字段([]int)
root_idx int- 字段(int)
err string- 错误
line int- 字段(int)
raw string- 字段(string)
i int- 下标或整数
(Doc) ok
用途
在 Doc 上执行 ok 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
返回值
bool — 是否成立
(Doc) error
pub fn (d Doc) error() string
用途
Doc 上的操作:错误。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
返回值
string — 结果字符串
(Doc) error_line
pub fn (d Doc) error_line() int
用途
Doc 上的操作:执行 error line 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
返回值
int — 该类型的值
(Doc) root
pub fn (d Doc) root() int
用途
在 Doc 上执行 root 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
返回值
int — 该类型的值
(Doc) valid_node
pub fn (d Doc) valid_node(n int) bool
用途
Doc 上的操作:执行 valid node 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) kind
pub fn (d Doc) kind(n int) int
用途
在 Doc 上执行 kind 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
int — 该类型的值
(Doc) is_dict
pub fn (d Doc) is_dict(n int) bool
用途
Doc 上的操作:判断是否 dict。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) is_list
pub fn (d Doc) is_list(n int) bool
用途
Doc 上的操作:判断是否 list。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) is_string
pub fn (d Doc) is_string(n int) bool
用途
Doc 上的操作:判断是否 string。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) is_number
pub fn (d Doc) is_number(n int) bool
用途
Doc 上的操作:判断是否 number。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) is_bool
pub fn (d Doc) is_bool(n int) bool
用途
Doc 上的操作:判断是否 bool。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) as_bool
pub fn (d Doc) as_bool(n int) bool
用途
Doc 上的操作:执行 as bool 操作。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) as_string
pub fn (d Doc) as_string(n int) string
用途
Doc 上的操作:执行 as string 操作。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
string — 结果字符串
(Doc) as_null
pub fn (d Doc) as_null(n int) int
用途
Doc 上的操作:执行 as null 操作。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
int — 该类型的值
(Doc) as_int
pub fn (d Doc) as_int(n int) int
用途
Doc 上的操作:执行 as int 操作。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
int — 该类型的值
(Doc) as_f64
pub fn (d Doc) as_f64(n int) f64
用途
Doc 上的操作:执行 as f64 操作。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
f64 — 该类型的值
(Doc) is_null
pub fn (d Doc) is_null(n int) bool
用途
Doc 上的操作:判断是否 null。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
bool — 是否成立
(Doc) text
pub fn (d Doc) text(n int) string
用途
Doc 上的操作:返回当前文本。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
string — 结果字符串
(Doc) key
pub fn (d Doc) key(n int) string
用途
Doc 上的操作:键。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
string — 结果字符串
(Doc) count
pub fn (d Doc) count(n int) int
用途
Doc 上的操作:统计非重叠出现次数。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
int — 该类型的值
(Doc) at
pub fn (d Doc) at(n int, i int) int
用途
在 Doc 上执行 at 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
i int- 下标或整数(int)
返回值
int — 该类型的值
(Doc) has
pub fn (d Doc) has(n int, key string) bool
用途
Doc 上的操作:是否具有。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
key string- 键(string)
返回值
bool — 是否成立
(Doc) dict_keys
pub fn (d Doc) dict_keys(n int) []string
用途
Doc 上的操作:执行 dict keys 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
[]string — 切片结果
(Doc) get
pub fn (d Doc) get(n int, key string) int
用途
在 Doc 上执行 get 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
key string- 键(string)
返回值
int — 该类型的值
(Doc) number_int
pub fn (d Doc) number_int(n int) int
用途
Doc 上的操作:执行 number int 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
int — 该类型的值
(Doc) number_f64
pub fn (d Doc) number_f64(n int) f64
用途
Doc 上的操作:执行 number f64 操作。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
f64 — 该类型的值
parse
pub fn parse(src &string) Doc
用途
解析输入。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
返回值
Doc — 该类型的值
parse_max
pub fn parse_max(src &string, max_bytes int) Doc
用途
解析为 max。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
max_bytes int- max_bytes(int)
返回值
Doc — 该类型的值
escape
pub fn escape(s &string) string
用途
转义。
参数
s &string- 源字符串(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
quote
pub fn quote(s &string) string
用途
加上引号并转义。
参数
s &string- 源字符串(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
unquote
pub fn unquote(s &string) string
用途
去掉引号并还原转义。失败时抛出错误,调用方需处理或继续传播。
参数
s &string- 源字符串(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
(Doc) to_json
pub fn (d Doc) to_json() string
用途
Doc 上的操作:转换为 json。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
返回值
string — 结果字符串
valid
pub fn valid(src &string) bool
用途
是否合法。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
返回值
bool — 是否成立
compact
pub fn compact(src &string) string
用途
压成一行。失败时抛出错误,调用方需处理或继续传播。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
indent
pub fn indent(src &string, prefix &string, gap &string) string
用途
缩进。失败时抛出错误,调用方需处理或继续传播。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
prefix &string- 前缀(只读借用,调用方仍持有原值;类型 &string)
gap &string- gap(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
html_escape
pub fn html_escape(src &string) string
用途
执行 html escape 操作。
参数
src &string- 源数据(只读借用,调用方仍持有原值;类型 &string)
返回值
string — 结果字符串
(Doc) encode
pub fn (d Doc) encode(n int) string
用途
Doc 上的操作:执行数据编码并返回结果。失败时抛出错误,调用方需处理或继续传播。
参数
d Doc- 本次调用使用的
Doc 实例;按值接收。
n int- 数量、长度或上限(int)
返回值
string — 结果字符串