모하메드 엘 Fwakhry :
나는 목록을 만들고 RecyclerView에 삽입이 JSON 변환하고자하지만 나에게 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"
}
}
]
MetaSnarf :
이에 대한 나의 접근 방식이 될 것입니다 :
GSON 라이브러리를 사용하여.
나는이 개 모델 클래스를 생성
- 각 배열 항목의 정보를 포함 할 기본 클래스
에 대한 최신 정보를 포함 할 사용자 지정 날짜 클래스
created_at
와updated_at
속성을class MyDate{ public String date; public int timezone_type; public String timezone }
class Info{ public String id; public String name_ar; ..//other properties//.. public MyDate created_at; public MyDate updated_at; }
다음 정보 클래스의 배열 목록에 JSON을 구문 분석
List<Info> infoArray = new Gson().fromJson(stringJson, new TypeToken<List<Info>>(){}.getType());