json数据处理

public static <T> T readJsonValue(String content, Class<T> valueType) {

ObjectMapper objectMapper =  new ObjectMapper();

        /*if (objectMapper == null) {

            objectMapper = new ObjectMapper();

        }*/

        try {

            return objectMapper.readValue(content, valueType);

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }

    public String encodeJson(Object boject){

        ObjectMapper objectMapper =  new ObjectMapper();

        String jsonStr = null;

        try {

            jsonStr = objectMapper.writeValueAsString(boject);

        } catch (JsonProcessingException e) {

            return jsonStr;

        }

        return jsonStr;

    }

//使用

 List<Map<String,String>> loanJsonList = MmmRequestHelper.readJsonValue(loanJsonListStr,  List.class);

List<Map> loanInfoList = new ArrayList<Map>();

String loanInfoJsonStr = MmmRequestHelper.encodeJson(loanInfoList);

猜你喜欢

转载自2914060970.iteye.com/blog/2306639