Erlang的Json库

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  
  1. JSON Obj    = type obj()   = {obj, [{key(), val()}]}  
  2. JSON Array  = type array() = [val()]  
  3. JSON Number = type num()   = int() | float()   
  4. JSON String = type str()   = bin()  
  5. JSON true false null       = true, false null (atoms)  
  6. With Type val() = obj() | array() | num() | str() | true | false | null  
  7. and key() being a str(). (Or a binary or atom, during JSON encoding.)  

  1. Eshell V5.6.3  (abort with ^G)  
  2. 1> O = rfc4627:encode({obj, [{name, hideto}, {age, 23}]}).  
  3. "{\"name\":\"hideto\",\"age\":23}"  
  4. 2> rfc4627:decode(O).  
  5. {ok,{obj,[{"name",<<"hideto">>},{"age",23}]},[]}  
  6. 3> A = rfc4627:encode([1,2,3,4,5]).  
  7. "[1,2,3,4,5]"  
  8. 4> rfc4627:decode(A).  
  9. {ok,[1,2,3,4,5],[]}  
  10. 5> N = rfc4627:encode(12345).  
  11. "12345"  
  12. 6> rfc4627:decode(N).  
  13. {ok,12345,[]}  
  14. 7> S = rfc4627:encode("12345").  
  15. "[49,50,51,52,53]"  
  16. 8> rfc4627:decode(S).  
  17. {ok,"12345",[]}  
  18. 9> T = rfc4627:encode(true).  
  19. "true"  
  20. 10> rfc4627:decode(T).  
  21. {ok,true,[]}  
  22. 11> F = rfc4627:encode(false).  
  23. "false"  
  24. 12> rfc4627:decode(F).  
  25. {ok,false,[]}  
  26. 13> Null = rfc4627:encode(null).  
  27. "null"  
  28. 14> rfc4627:decode(Null).  
  29. {ok,null,[]}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值