我想将这个JSON转换为列表并插入RecyclerView中,但是我不能,因为它给了我3个类.
因此,如何将此类转换为父类?谁能帮助我,以便我列出要放入RecyclerView的响应列表.
[
{
"id": 114,
"name_ar": "محمصه زين",
"latitude": null,
"longitude": null,
"name_en": "Mohamsa Zein",
"description_ar": "",
"description_en": "",
"phone": null,
"mobile": "01110881085",
"address_ar": "مدينتى، Egypt",
"address_en": "مدينتى، Egypt",
"photo": "5b7958dc1c3661534679260.jpg",
"album": null,
"created_at": {
"date": "2018-08-19 11:47:40.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-10-23 11:00:22.000000",
"timezone_type": 3,
"timezone": "UTC"
}
},
{
"id": 184,
"name_ar": "محل عصائر فيرتاس",
"latitude": null,
"longitude": null,
"name_en": "Varieties For Juice",
"description_ar": "",
"description_en": "",
"phone": null,
"mobile": "01024229935",
"address_ar": "مدينتى، Egypt",
"address_en": "مدينتى، Egypt",
"photo": null,
"album": null,
"created_at": {
"date": "2018-10-28 11:40:54.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-01-02 08:36:04.000000",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
解决方法:
我对此的处理方法是:
使用GSON库.
我创建了两个模型类
>包含每个数组项信息的主类
>自定义日期类,其中将包含您的日期信息
created_at和updated_at属性
MyDate类{
公共字符串日期;
public int timezone_type;
公共字符串时区
}
类别信息{
公共字符串ID;
public String name_ar;
..//其他属性// ..
公共MyDate created_at;
公共MyDate Updated_at;
}
然后将json解析为Info类的数组列表
List<Info> infoArray = new Gson().fromJson(stringJson, new TypeToken<List<Info>>(){}.getType());