Json-rpc的JsonArray比Json-lib 的JsonArray

 http://www.java125.cn/article.asp?id=1994

 

1.json-rpc里的jsonArray一般要这么拿数据,再包装
JSONArray cgs = new JSONArray();
  Collection<RecruitmentVO> categories = informationDAO.getAllInformation();
  for(RecruitmentVO c : categories){   
   JSONObject o = new JSONObject();
   o.put("id", c.getId());
   o.put("title", c.getCompanyName());
   cgs.put(o);
  }
  return cgs.toString();

2.用了json-lib的JsonArray,一切很方便
   List<AjSaryxx> list = saryService.queryDBSaryxxRseultList(zjxx,pageInfo);
   JSONArray jsonArray = JSONArray.fromObject(list);        

接着List里有什么, JSONArray就转为相对应的Json

 

JSON

 

 

Java

 

string

 

<=>

 

java.lang.String, java.lang.Character, char

 

number

 

<=>

 

java.lang.Number, byte, short, int, long, float, double

 

true|false

 

<=>

 

java.lang.Boolean, boolean

 

null

 

<=>

 

null

 

function

 

<=>

 

net.sf.json.JSONFunction

 

array

 

<=>

 

net.sf.json.JSONArray (object, string, number, boolean, function)

 

object

 

<=>

 

net.sf.json.JSONObject

 


工具帮你完成转换.
稍为不是很方便的是. json-lib-1.5.jar需要以下jar. 一个一个找对版本才能用. 网站就没有一个打包好的..

  • jakarta commons-lang 2.3
  • jakarta commons-beanutils 1.7.0
  • jakarta commons-collections 3.2
  • jakarta commons-logging 1.1
  • ezmorph 1.0.3

你可能感兴趣的:(Json-rpc的JsonArray比Json-lib 的JsonArray)