方法

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());
Last modification:August 6, 2019
If you think my article is useful to you, please feel free to appreciate