Parsing Android JSON response from server
-
I've come up with such an interesting (interested) response from the JSON server.
{ "addressData": [ { "id": 2223, "name": "Респ Дагестан, г Махачкала", "description": "2мик. 434дом", "house_number": "", "flat_number": "", "created_at": "2015-08-21T13:01:13.000Z", "updated_at": "2015-08-21T13:01:13.000Z", "user_id": 20, "changed_user_id": null, "city": "Махачкала" }, { "id": 2224, "name": "Респ Дагестан, г Махачкала", "description": "2мик. 597дом", "house_number": "", "flat_number": "", "created_at": "2015-08-21T13:05:51.000Z", "updated_at": "2015-08-21T13:05:51.000Z", "user_id": 20, "changed_user_id": null, "city": "Махачкала" }, { "id": 2225, "name": "Респ Дагестан, г Махачкала", "description": "3 микр. дом 648", "house_number": "", "flat_number": "", "created_at": "2015-09-17T17:52:46.000Z", "updated_at": "2015-09-17T17:52:46.000Z", "user_id": 20, "changed_user_id": null, "city": "Махачкала" } ], "newspaperData": [ { "id": 1, "name": ""Ас-Салам" на русском", "manufacturer_id": 1, "created_at": "2015-06-23T16:21:45.000Z", "updated_at": "2015-06-23T16:21:45.000Z" }, { "id": 2, "name": ""Ас-Салам" на аварском", "manufacturer_id": 1, "created_at": "2015-06-23T16:21:56.000Z", "updated_at": "2015-06-23T16:21:56.000Z" }, { "id": 3, "name": ""Ас-Салам" на лезгинском", "manufacturer_id": 1, "created_at": "2015-07-11T12:56:50.000Z", "updated_at": "2015-07-11T12:56:50.000Z" } ], "subscriberData": [ { "id": 1111, "name": "Гаджи", "surname": "Гаджиев", "email": "", "description": "", "user_id": 20, "changed_user_id": null, "real_status": null, "created_at": "2015-08-21T13:01:13.000Z", "updated_at": "2015-08-21T13:01:13.000Z", "main_phone": "", "additional_phone": "", "delete_on": null, "where_added": "user", "added_user_id": null }, { "id": 1112, "name": "Шамиль", "surname": "Ибрагимов", "email": "", "description": "", "user_id": 20, "changed_user_id": null, "real_status": null, "created_at": "2015-08-21T13:05:51.000Z", "updated_at": "2015-08-21T13:05:51.000Z", "main_phone": "", "additional_phone": "", "delete_on": null, "where_added": "user", "added_user_id": null }, { "id": 1113, "name": "Арсланали", "surname": "Исаев", "email": "", "description": "", "user_id": 20, "changed_user_id": null, "real_status": null, "created_at": "2015-09-17T17:52:46.000Z", "updated_at": "2015-09-17T17:52:46.000Z", "main_phone": "", "additional_phone": "", "delete_on": null, "where_added": "user", "added_user_id": null } ], "subscriptionPeriodData": [ { "id": 3874, "period_start": "01.01.2015", "period_finish": "31.12.2015", "description": "", "created_at": "2015-08-21T13:01:13.000Z", "updated_at": "2015-12-04T17:17:06.000Z", "subscriber_id": 1111, "user_id": 20, "address_id": 2223, "changed_user_id": null, "newspaper_id": 1, "price_paid": 0, "price": 0 }, { "id": 3875, "period_start": "01.07.2015", "period_finish": "31.12.2015", "description": "", "created_at": "2015-08-21T13:05:51.000Z", "updated_at": "2015-12-04T17:17:06.000Z", "subscriber_id": 1112, "user_id": 20, "address_id": 2224, "changed_user_id": null, "newspaper_id": 2, "price_paid": 0, "price": 0 }, { "id": 5172, "period_start": "01.07.2015", "period_finish": "31.12.2015", "description": "", "created_at": "2015-09-17T17:52:46.000Z", "updated_at": "2015-12-04T17:17:09.000Z", "subscriber_id": 1113, "user_id": 20, "address_id": 2225, "changed_user_id": null, "newspaper_id": 3, "price_paid": 0, "price": 0 } ] }
The answer from the server is to match the tables with field ID. We need to get the name of the Spokesman, the name of the Gusettes, the address of the Gazettes. The main table with which everything is connected is subscriptionPeriodData. Who's got a way to tie ID and get the result out?
-
Used http://square.github.io/retrofit/ for online requests. Create models and report back to the gson.