json解析為泛型對象


一、方法

public <T> T jsonToObjByType(String str, Type type) {
    try {
        if (isValidJson(str)) {
            return gson.fromJson(str, type);
        }
    } catch (JsonSyntaxException e) {
        System.out.println(e.getMessage());
    }
    return null;
}            

 

二、調用示例

MsgResponse<List<MTb>> rsp = new JsonUtil().jsonToObjByType(s, new TypeToken<MsgResponse<List<MTb>>>() {}.getType());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM