Erlang的JSON库
关键字: erlang json 使用下列JSON库:http://www.lshift.net/blog/2007/02/17/json-and-json-rpc-for-erlang
该JSON库采用 Joe Armstrong prefered Data type mapping
- JSON Obj = type obj() = {obj, [{key(), val()}]}
- JSON Array = type array() = [val()]
- JSON Number = type num() = int() | float()
- JSON String = type str() = bin()
- JSON true false null = true, false null (atoms)
- With Type val() = obj() | array() | num() | str() | true | false | null
- and key() being a str(). (Or a binary or atom, during JSON encoding.)
- Eshell V5.6.3 (abort with ^G)
- 1> O = rfc4627:encode({obj, [{name, hideto}, {age, 23}]}).
- "{\"name\":\"hideto\",\"age\":23}"
- 2> rfc4627:decode(O).
- {ok,{obj,[{"name",<<"hideto">>},{"age",23}]},[]}
- 3> A = rfc4627:encode([1,2,3,4,5]).
- "[1,2,3,4,5]"
- 4> rfc4627:decode(A).
- {ok,[1,2,3,4,5],[]}
- 5> N = rfc4627:encode(12345).
- "12345"
- 6> rfc4627:decode(N).
- {ok,12345,[]}
- 7> S = rfc4627:encode("12345").
- "[49,50,51,52,53]"
- 8> rfc4627:decode(S).
- {ok,"12345",[]}
- 9> T = rfc4627:encode(true).
- "true"
- 10> rfc4627:decode(T).
- {ok,true,[]}
- 11> F = rfc4627:encode(false).
- "false"
- 12> rfc4627:decode(F).
- {ok,false,[]}
- 13> Null = rfc4627:encode(null).
- "null"
- 14> rfc4627:decode(Null).
- {ok,null,[]}