我有以下 JSON 数据:
{
"response": {},
"errorMessage": {
"error": [
{
"errorId": 260003,
"domain": "ads",
"subdomain": "asd",
"severity": "asd",
"category": "asd",
"message": "asdsa asd ad",
"errorName": "UnAuthorized"
}
]
}
}
目前我有以下类结构:
public class JSONCollection
private Response response;
private ErrorMessage error;
public class Response
private String collectionId;
private String url;
public class ErrorMessage
private List<ErrorValues> error;
public class ErrorValues
private String errorId;
private String domain;
private String subdomain;
private String severity;
private String category;
private String message;
private String errorName;
我为所有私有(private)变量设置了 setter/get
但是当我执行 JSONCollection cJson = gson.fromJson(JSONValue,JSONCollection.class);
时,我得到的 cJson 为 null
。
如何做到正确?
最佳答案
我用了this tool由 @JigarJoshi 显示来生成我的架构。
我发现的唯一区别是我必须将类名从 ErrorValues
更改为 Error
关于java - 我的类结构应该是什么来解析 GSON 中的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17794916/