json(JavaScript Object Notation) 是一种轻量级的数据交换格式。
一、两种结构
1、 "名称/值",无序 #key/value { key:value, ...}
2、 "值的有序列表" #数组(array) [value, ...]
二、值(value)的类型
1、string ""
2、number
3、true/false
4、null
5、对象(object)
6、数组(array)
~mark/software/lua-cjson-manual.html
cjson:
解码(decode): #json -> lua
> json_text = '[true, {"foo":"bar"}]'
> lua_value = cjson.decode(json_text) => Returns: {true, {foo="bar"}}
编码(encode): #lua -> json
> lua_value = {true, {foo="bar"}}
> json_text = cjson.encode(lua_value) => Returns: '[true, {"foo":"bar"}]'
===============================
> temp.k = 100000000000000
> print(temp.k)
1e+14
> temp.k = 99999999999999
> print(temp.k)
99999999999999
>
> for k, v in pairs(temp) do
>> print(k, v)
>> end
k 99999999999999
v 1000
bbs 10000
>
> print(cjson.encode(temp))
{"k":99999999999999,"v":1000,"bbs":10000}
> print(cjson.encode_sparse_array())
false 2 10
>
> print(cjson.encode {[11] = "data"})
stdin:1: Cannot serialise table: excessively sparse array
stack traceback:
[C]: in function 'encode'
stdin:1: in main chunk
[C]: at 0x004040c0
> print(cjson.encode_sparse_array(true))
true 2 10
> print(cjson.encode {[11] = "data"})
{"11":"data"}