Updated 1 September 2017
In this blog, we will know how to convert JSON Array response data to a model through the Retrofit Callback?
As we know that Retrofit Library is a REST Client for Android and Java by Square. It makes relatively easy to send and retrieve JSON (or other structured data) via rest Webservice. In Retrofit, we can configure which converter is used for the data serialization.
The answer is that we just pass a List of model class and Retrofit convert JSON Array object to the corresponding Model class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[ { "id": "1", "title": "discount", "type": "C", "type_data": "167", "content": "discount", "status": "A", "time": "1480417496" }, { "id": "2", "title": "Offer", "type": "P", "type_data": "12", "content": "New Year Offer", "status": "A", "time": "1480417516" } ] |
1 2 3 4 5 6 |
@GET(MOBIKUL_NOTIFICATION_DATA) Call<List<NotificationResponse>> getNotificationData( @Header("Authorization") String authkey , @Query("lang_code") String langCode , @Query("currency_code") String currencyCode ); |
1 2 3 4 5 6 7 8 |
public static void getNotificationData(Context mContext, Callback<List<NotificationResponse>> callback){ Call<List<NotificationResponse>> call = RetrofitClient.getClient(mContext).create(ApiInterface.class).getNotificationData( Helper.getAuthToken() , AppSharedPref.getLanguageCode(mContext) , AppSharedPref.getCurrencyCode(mContext) ); call.enqueue(callback); } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.