mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 11:08:34 +08:00
1.2 KiB
1.2 KiB
JSON 扩展函数
1.json_load
加载 json 数据。
原型
json_load(str) => object
json_load(binary) => object
json_load(data, size) => object
2.json_save
保存 json 数据。
原型
json_save(obj, filename) => bool
3.ubjson_load
加载 ubjson 数据。
原型
ubjson_load(binary) => object
ubjson_load(data, size) => object
4.ubjson_save
保存 ubjson 数据。
原型
ubjson_save(obj, filename) => bool
完整示例
//load from string
a=json_load('
{
"name":"fscript",
"age":100
}
')
assert(object_get(a, "name")=="fscript");
assert(object_get(a, "age")==100);
//save to file
b=json_save(a)
assert(file_write("test.json", b))
//load from file as text
a = json_load(file_read_text("test.json"))
assert(object_get(a, "name")=="fscript");
assert(object_get(a, "age")==100);
//load from file as binary
a = json_load(file_read_binary("test.json"))
assert(file_remove("test.json"))
assert(object_get(a, "name")=="fscript");
assert(object_get(a, "age")==100);
assert(file_remove("test.json"))
unset(a)
unset(b)