1

こんにちは私のjsonはこのようなもので、Javaへの変換にgsonを使用しました。すべての属性を持つトップレベルのクラスと、リストを持つ別のクラスを作成しました。ただし、配列サイズが正しい場合でも、値はnullとして出力されます。私は何が間違っているのですか?


Gson json = new Gson();
ProductListResponse [] response = json.fromJson(str, ProductListResponse[].class);

public class ProductList {

    public String code;
    public String name;
    public String description;
    public Date lastUpdateDate;
    public String lastUpdatedBy;        

}
------------------------------------------------------------------------------------

public class ProductListResponse {

    public ProductList plist;   

}
-------------------------------------------------------------------------------------------

[
    {
        "product": {
            "code": "RA",
            "name": "Read About",
            "description": "Read About"
        }
    },
    {
        "product": {
            "code": "READ180",
            "name": "Read180",
            "description": "Read180"
        }
    },
    {
        "product": {
            "code": "RLIB",
            "name": "Read180 Library Catalog",
            "description": "Read180 Library Catalog",
            "last_udapte_date": "2010-12-07 00:00:00.0",
            "last_updated_by": "fdixon00"
        }
    },
    {
        "product": {
            "code": "EREADS",
            "name": "Read180 eReads",
            "description": "Read180 eReads"
        }
    },
    {
        "product": {
            "code": "RSKILL",
            "name": "Read180 rSkills",
            "description": "Read180 rSkills",
            "last_udapte_date": "2010-09-20 00:00:00.0",
            "last_updated_by": "fdixon00"
        }
    },
    {
        "product": {
            "code": "POOL",
            "name": "Reference Asset Pool",
            "description": "Reference Asset Pool"
        }
    },
    {
        "product": {
            "code": "SU",
            "name": "Scholastic U",
            "description": "Scholastic U"
        }
    },
    {
        "product": {
            "code": "TR8TS",
            "name": "Six Traits of Writing",
            "description": "Six Traits of Writing"
        }
    },
    {
        "product": {
            "code": "TFX",
            "name": "TrueFlix",
            "description": "TrueFlix",
            "last_udapte_date": "2012-08-20 10:47:46.0",
            "last_updated_by": "wbyler00"
        }
    }
]
4

1 に答える 1

2

それはただのネーミングの混乱です: に名前をProductListResponse変更plistするproductと、すぐに機能します。

于 2012-09-29T00:13:25.217 に答える