Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5014516
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: Python/Ruby

2012-08-24 07:23:00

使用下列JSON库:
http://www.lshift.net/blog/2007/02/17/json-and-json-rpc-for-erlang

该JSON库采用
即:

  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,[]}


阅读(1874) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~