是否可以使用Model类在JSONArray内部序列化JSONArray?

时间:2019-06-24 09:56:44

标签: android arrays json serialization

我想使用GSon库将JSONArray序列化为ArrayList,结果结构为JSONArray-> JSONArray-> JSONObject

//I have tried this,
try {
    Gson gson = new Gson();
    Type placeOrdersListType = new 
TypeToken<List<PlaceOrderMaster>> 
() {
}.getType();
List<PlaceOrderMaster> placeOrdersTypeList = 
gson.fromJson(jsonObject
.getJSONArray(ResponseParams.RESULT).toString(), 
placeOrdersListType);
ArrayList<PlaceOrderMaster> arrayList = new ArrayList<> 
(placeOrdersTypeList);
} catch (Exception e) {
    e.printStackTrace();
} 

//and my model class is like this,
private ArrayList<ArrayList<PlaceOrders>> result;

// API Response like this
{
"status": 1,
"message": "Order Placed successfully!!!",
"result": [
    [
        {
            "orderid": "1841",
            "category_id": "8"
        },
        {
            "orderid": "1841",
            "category_id": "1"
        }
    ],
    [
        {
            "orderid": "1842",
            "category_id": "6"
        },
        {
            "orderid": "1842",
            "category_id": "6"
        }
    ]
]
}

是否可以序列化API响应>?如果是,那怎么办?

0 个答案:

没有答案