歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> JSON對象數組到Java的轉換

JSON對象數組到Java的轉換

日期:2017/3/1 10:27:52   编辑:Linux編程

json用來在客戶端和服務器端之間傳輸數據很是簡潔和方便,但是如果客戶端傳輸的是對象數組的話,得做如下的處理:

  1. JSONArray testJSONArray=JSONArray.fromObject(testArrayStr);
  2. Collection testArray=JSONArray.toCollection(testJSONArray);
  3. if(testArray!=null && !testArray.isEmpty())
  4. {
  5. Iterator it=testArray.iterator();
  6. while(it.hasNext())
  7. {
  8. JSONObject testJSONObj=JSONObject.fromObject(it.next());
  9. Test test=(Test) JSONObject.toBean(testJSONObj,Test.class);
  10. ...
  11. }
  12. }

JSON包下載 http://sourceforge.net/projects/json-lib/

Copyright © Linux教程網 All Rights Reserved