android retrofit example json

Get JSON Array using Retrofit Android Example

I used volley and Retrofit on my project as per project requirement. In this retrofit android example article I am going to show you how to get JSON object or JSON Array from URL using Retrofit library. So first understand the benefit of both the Libraries to make HTTP calls.

Volley Library is build by Google and Retrofit is build be Square. Retrofit is definitely the better alternative to volley in terms of ease of use, performance, flexibility and other things. Using this tool android developer can make all network stuff much more easier.

Use Android Retrofit if your project is based on a standard REST API with JSON responses. Use Volley is really good in terms of Caching and Retries.

One important point that you have to keep remember if you want to download large files or streaming then don’t use any of Retrofit or Volley. Go for Download Manager because large files require buffers and resume features.

Watch Video Retrofit Android Example

Before start coding please look at the JSON object File and JSON Array File that I will use during this project. You can create your own JSON file ar per need. Here is my JSON Object and JSON Array File. You have to add Retrofit library dependency on app gradle file. There you have to use JSON converter library to get actual value from json file.

Step by Step Guide

1) Add Dependency on Gradle file
2) Understand Retrofit structure
3) Create Model(POJO) class
4) Create Interface (Service) for Retrofit
5) Create Retrofit CallBack Request from Main Activity
6) Run App in Real Device using USB Debugging


Login & Download source code


50 days android course


Add Dependency on Gradle file

Create New Project in android studio. My project name is Retrofit_json. Now open app module gradle file and add following dependency in dependency section.

Add Internet Permission in Android Manifest file

Understand Retrofit Structure

Retrofit Library is work on three steps. First is Model class that is POJO model. You have to create all the variable name that are present on your JSON file. For example in my JSON file there are string name as “rom” and “screenSize”, so I created string type variable with same name in my model class. Remember String name must be same otherwise it will not work.

Second is Interface or Service that we have to call from main activity. You have to define your sub-url from where you want json data, Callback return type and the method name in this Interface file.

android retrofit 2 json

Third is Retrofit request queue. You have to make request from make activity by initializing retrofit and interface. The response will be return on the format that you will define in return type in retrofit interface.

Create Model(POJO) class

Create new Java class and name it as Create all the string, integer and object variable that present on your json file. below is my class

Create Interface (Service) for Retrofit

You can create multiple interface as per your need. I am creating two interface- one for JSON Object and one for JSON Array. In this Interface you have to write four point. 1) GET/POST method type 2) Sub-url string from where you want to fetch json data 3) method name- give it any name. 4) Callback return type – it will be model type of list of model type.

If your JSON file in object type than interface callback return type will Model only. If you JSON file in Array type than the return type will be list.

Create Retrofit CallBack Request from Main Activity

Now the final thing is to create retrofit variable and call the Interface methods. To initialize retrofit variable, you have to pass BaseURL means your website primary domain name and JSON converter. Now initialize interface and call the method inside interface. The final step is call.enqueue request that will return response in Model type on OnResponse method. Below is complete code of file


Run the Code in Real Device using USB Debugging

Now you have to run this code. You will see json reponse in logcat. I have placed one Textview on activity.xml file to display the response on screen. I hope after learn from this Retrofit android example article, you can easily get json array, image and string from URL using Retrofit library.

Please leave your comment about video lesson and what more you want to learn from me.

Read MoreCreate Facebook Messenger type Floating Icon and Send FCM Notification to Device

50 days android course





Posted in andorid.

kamal bunkar

I Am Post Graduation (M.Tech. C.S.E) from VNIT, Nagpur. I Have Published Two Research Paper On International Journal. My Apps on Google Play Store- Sanyukt Parivar(Mp Police ), NOTOtag- Digital Chhindwara, The Tubby-VoiceRecognizer & More.
Contact me at

One Comment

  1. Pingback: The Simplest Way to Get WordPress Post in Android App - BlueApp Software Blog

Leave a Reply

Your email address will not be published. Required fields are marked *