1

I am sorry but i couldn't even phrase the question well but here it goes. I am getting a JSON response like this:

{
    "results": {
        "b2bc01": [{
            "message": "Successfully created",
            "_id": "596c8b25ce2350e41600002f",
            "status": "Success",
            "code": 200
        }],
        "b2bc02": [{
            "message": "Successfully created",
            "_id": "596c8b25ce2350e416000030",
            "status": "Success",
            "code": 200
        }]
        .
        .
        .
        "b2bc0n":[{
            "message": "Successfully created",
            "_id": "596c8b25ce2350e416000030",
            "status": "Success",
            "code": 200
            }]
    }
}

How do i create POJO class for this type of JSON. I tried in jsonschema2pojo but i feel its not a good result. Please help. Thank in advance

4

2 回答 2

2

你的 POJO 文件

class MyPojo {
    HashMap<String, ArrayList<MyModel>> results;

    class MyModel {
        String message;
        String _id;
        String status;
        int code;
    }
于 2018-06-29T19:07:27.903 回答
0

您只能对这些数据使用 pojo:

[{
            "message": "Successfully created",
            "_id": "596c8b25ce2350e41600002f",
            "status": "Success",
            "code": 200
        }]

如果你使用改造 2 和 gson,我建议你使用接口 JsonDeserializer

使用 .registerTypeAdapter()

例子

Gson gson = new GsonBuilder()
                            .excludeFieldsWithoutExposeAnnotation()
                            .registerTypeAdapter(GpcProductDetail.class, new GpcProductDeserializer())
                            .create();

并手动解析 json 的那部分。

于 2018-06-29T19:45:08.677 回答