教父的告白
一切都是纸老虎
posts - 82,  comments - 7,  trackbacks - 0
使用下列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       = truefalse 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,[]}  

posted on 2009-09-18 15:38 暗夜教父 阅读(2997) 评论(0)  编辑 收藏 引用 所属分类: erlang

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜