Gson.fromJson格式的java类

时间:2016-06-09 15:35:28

标签: java json gson

我有一个像这样的json字符串:

{
"user-TESTING": [{
    "name": "SERVICE",
    "label": "another test",
    "tags": [],
    "credentials": {
        "PASSWORD": "TestMe",
        "NAME": "http://www.blahblah",
        "USER": "TEST"
    },
    "syslog_url": ""
}]

}

我如何格式化课程,以便使用gson.fromJson(<jsonString>, <class>)

1 个答案:

答案 0 :(得分:1)

class Something
{
    @SerializedName("user-TESTING")
    User[] user;

    static class User
    {
        String name;
        String label
        String[] tags;
        Credentials credentials;
        String syslog_url;
    }

    static class Credentials
    {
        String PASSWORD;
        String NAME;
        String USER;
    }
}

我不知道标签的内容,所以我猜到了String。