mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-05 05:27:58 +08:00
42 lines
714 B
Markdown
42 lines
714 B
Markdown
|
## JSON 扩展函数
|
||
|
|
||
|
### 1.json\_load
|
||
|
### 2.json\_save
|
||
|
### 3.ubjson\_load
|
||
|
### 4.ubjson\_save
|
||
|
|
||
|
```js
|
||
|
//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)
|
||
|
```
|
||
|
|