什么应该是我的类结构来解析GSON中的JSON

时间:2013-07-22 18:37:11

标签: java json parsing gson

我有以下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

如何做到对不对?

1 个答案:

答案 0 :(得分:1)

我使用@JigarJoshi显示的this tool来生成我的架构。

我找到的唯一区别是我必须将班级名称从ErrorValues更改为Error

相关问题