【发布时间】:2013-07-22 18:37:11
【问题描述】:
我有以下 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;
我为所有私有变量设置了 setter/get
但是当我执行 JSONCollection cJson = gson.fromJson(JSONValue,JSONCollection.class); 时,我得到 cJson 作为 null。
如何做到正确?
【问题讨论】:
-
Use this tool 为您的 JSON 生成架构
-
@JigarJoshi 当我用我的 JSON 按下预览时,什么都没有显示
-
它对我有用,将您的 JSON 粘贴到该字段中,选择源类型 = JSON,注释样式 = 无