日期:2014-05-16  浏览次数:20370 次

javabean转化json, json转换为javabean
User user = new User();
user.setId("1");
user.setName("wan");
System.out.println(JSONObject.fromObject(user).toString());


String str2 =  "{\"id\":\"1\",\"name\":\"wan\"}";
JSONObject jsonObject = JSONObject.fromObject(str2);
User user2 = (User)JSONObject.toBean(jsonObject, User.class);

?

采用的json库是json-lib库(下载地址:http://json-lib.sourceforge.net/),该库还需要

  • jakarta commons-lang 2.4
  • jakarta commons-beanutils 1.7.0
  • jakarta commons-collections 3.2
  • jakarta commons-logging 1.1.1
  • ezmorph 1.0.6