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

xcitsw88  于 2023-02-26  发布在  其他
关注(0)|答案(1)|浏览(159)

我有以下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 set
但是当我做JSONCollection cJson = gson.fromJson(JSONValue,JSONCollection.class);时,我得到的cJson是null
如何做好呢?

zzoitvuj

zzoitvuj1#

我使用@JigarJoshi所示的this tool来生成我的模式。
我发现的唯一区别是必须将类名从ErrorValues更改为Error

相关问题