java json字串轉換為物件,轉換為list

yangxi_001發表於2014-04-16
json字串轉換為物件
JSONObject jo =JSONObject.fromObject(sysNumberRuleJsonStr);//這一步報錯(執行時):The constructor JSONObject(String) is undefined
應改為:
JSONObject jo = new JSONObject();
JSONObject jsonObject = jo.fromObject(sysNumberRuleJsonStr);
SysNumberRule rule = (SysNumberRule) JSONObject.toBean(jo, SysNumberRule.class);
request.setAttribute("sysNumberRule", rule);
json字串轉換為list
String sysNumberRuleRows = request.getParameter("sysNumberRuleRows");
List<SysNumberRule> list = new ArrayList<SysNumberRule>();
JSONArray json = JSONArray.fromObject(sysNumberRuleRows);
rowslist = JSONArray.toList(json, SysNumberRule.class);
or
rowslist = JSONArray.toCollection(json, SysNumberRule.class);

相關文章