public static void JacksonTest() {//推荐 //{"MNG001":[{"ID":"1","PWD":"2"}],"MNG002":[{"FaultCode":"1","PWD":"3"}]} String json = "{"MNG001":[{"ID":"1","PWD":"2"}],"MNG002":[{"FaultCode":"1","PWD":"3"}]}"; ObjectMapper mapper = new ObjectMapper(); //把json字符串转为对象 Object object = null; try { object = mapper.readValue(json, Object.class); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } System.out.println("JsonToObject-->"+object.toString()); //把对象转为json字符串 String objectjson = ""; try { objectjson = mapper.writeValueAsString(object); } catch (JsonProcessingException e) { e.printStackTrace(); } System.out.println("ObjectToJson-->"+objectjson); } public static void GsonTest() { //{"MNG001":[{"ID":"1","PWD":"2"}],"MNG002":[{"FaultCode":"1","PWD":"3"}]} String json = "{"MNG001":[{"ID":"1","PWD":"2"}],"MNG002":[{"FaultCode":"1","PWD":"3"}]}"; Gson gson = new Gson(); //把json字符串转对象 Object object = gson.fromJson(json, Object.class); System.out.println("JsonToObject-->"+object.toString()); //把对象转json字符串 String objectjson = gson.toJson(object); System.out.println("ObjectToJson-->"+objectjson); }