`
dcaoyuan
  • 浏览: 309321 次
社区版块
存档分类
最新评论

UBF vs JSON

阅读更多
UBF(B) is the contract, it's almost erlang code:
java 代码
  1. +TYPES  
  2.   person() = {person,  
  3.               firstname(),  
  4.               lastname(),  
  5.               sex(),  
  6.               age()};  
  7.   firstname() = string();  
  8.   lastname() = string();  
  9.   age() = int();  
  10.   sex() = male | female;  
  11.   people() = [person()].  

UBF(A) is the binary encoding.
In UBF(A), spaces are optional. Example for type people():
java 代码
  1. ’person’ >p  
  2. # {p "jim" "smith" ’male’ 10} &  
  3.   {p "susan" "jones" ’female’ 14} & $  

In UBF(A), the order of data makes sense,  thus, UBF is not data order free.

In JSON, it will be:
js 代码
  1. {"person": [{"firstname":"jim","lastname":"smith","sex":"male","age":"10"},  
  2.             {"firstname":"susan","lastname":"jones","sex":"female","age":"14"}]}  

In JSON, the order of data is free.

In XML, it will be:
xml 代码
  1. <people>  
  2.   <person>  
  3.     <firstname>jim<!---->firstname>  
  4.     <lastname>smith<!---->lastname>  
  5.     <sex>male<!---->sex>  
  6.     <age>10<!---->age>  
  7.   <!---->person>  
  8.   <person>  
  9.     <firstname>susan<!---->firstname>  
  10.     <lastname>jones<!---->lastname>  
  11.     <sex>female<!---->sex>  
  12.     <age>14<!---->age>  
  13.   <!---->person>  
  14. <!---->people>  

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics