JSON对象与JSON字符串之间的转换
JSON引用包:import net.sf.json
1、JSON字符串转JSON对象(例子中的AgencyExpand是java对象)
JSONObject json = JSONObject.fromObject(str);
//处理JSONObject转对象,时间总是默认当前系统时间问题
JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(new String[] {"yyyy-MM-dd"}));
AgencyExpand agencyExpand = (AgencyExpand)JSONObject.toBean(json,AgencyExpand.class);
//JSON对象转字符串
json.toString();
2、Java对象转JSON对象
JSONObject json = JSONObject.fromObject(AgencyExpand);
3、JSON字符串转JSON对象数组
JSONArray jsonArray = JSONArray.fromObject(str);
List<AgencyExpand> paramList=jsonArray.toList(jsonArray, AgencyExpand.class);
4、Java对象列表转JSON对象数组
JSONArray array = JSONArray.fromObject(list);