Json-lib 的JsonArray比Json-rpc的JsonArray用起來爽
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.queryDBSaryxxRseult
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