awtk/tests/fscripts/demo_ubjson.fs

29 lines
580 B
Forth
Raw Normal View History

2021-01-07 16:17:01 +08:00
//create a json
2022-08-23 11:21:48 +08:00
var a=json_load('
2021-01-07 16:17:01 +08:00
{
"name":"fscript",
"age":100
}
')
assert(object_get(a, "name")=="fscript")
assert(object_get(a, "age")==100)
//save as ubjson
2022-08-23 11:21:48 +08:00
var b=ubjson_save(a)
2021-01-07 16:17:01 +08:00
print(b)
//load from buffer
a = ubjson_load(b)
assert(object_get(a, "name")=="fscript")
assert(object_get(a, "age")==100)
//load from file as binary
assert(file_write("test.ubjson", b))
a = ubjson_load(file_read_binary("test.ubjson"))
assert(file_remove("test.ubjson"))
assert(object_get(a, "name")=="fscript")
assert(object_get(a, "age")==100)
assert(file_remove("test.ubjson"))