GSON jar包:http://code.google.com/p/google-gson/
//java object to json public String toJson(Object obj){ Gson gson = new Gson(); return gson.toJson(obj); }
//json to java object public Object toObject(String jsonStr, Class c){ Gson gson = new Gson(); return gson.fromJson(jsonStr, c); }
jackson jar 包: http://jackson.codehaus.org/
//java object to json public String toJson(Object obj){ ObjectMapper om = new ObjectMapper (); return om.writeValueAsString(obj); }
//json to java object public Object toObject(String json, Class c){ ObjectMapper mapper = new ObjectMapper(); User user = mapper.readValue(json, c); }