JackJSON 생성 및 JSON을 구문 분석

도 1에서, 선두 패킷
하여 jackjson 세 메쉬 프로젝트 LIB로 패키지 JAR (패키지가 업로드),도 2에 도시 된 스크린 샷 :
여기에 그림 삽입 설명
2, JackJsonUtils가 발생하여 데이터의 JSON JSON 데이터를 파싱 코드 :

public class JackJsonUtils {  
    static ObjectMapper objectMapper;  
    /** 
     * 解析json 
     *  
     * @param content 
     * @param valueType 
     * @return 
     */  
    public static <T> T fromJson(String content, Class<T> valueType) {  
        if (objectMapper == null) {  
            objectMapper = new ObjectMapper();  
        }  
        try {  
            return objectMapper.readValue(content, valueType);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
  
    /** 
     * 生成json 
     *  
     * @param object 
     * @return 
     */  
    public static String toJson(Object object) {  
        if (objectMapper == null) {  
            objectMapper = new ObjectMapper();  
        }  
        try {  
            return objectMapper.writeValueAsString(object);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
}  

추천

출처blog.csdn.net/sjn0815/article/details/92622177