How to Get JSON data using retrofit in Android

Hello guys, Welcome to our tutorial. In this tutorial will get JSON response and to parse it for further use.

In android we need to store data on server since we cannot store all the data in Sql Lite. Suppose we have stored data on server but want to retrieve it. So in this tutorial we are going to get data from server. In this application we are using third party API to get data. So without further ado lets start with this tutorial.

In order to start we have to add Retorfit and GSON dependency in our project. We can do it by add below lines in gradle.app.

After adding it sync the project. Now we are ready to go.

Building Android application.

  • Adding permission.

In order to work with API we have to add INTERNET permission. Below is the AndroidManifest file with internet permission.

  • Creating User Interface

Design a layout to suit your functionality. Here we have designed simple layout.

Get JSON data using retrofit in android screenshot

  • Response Class

Design a POJO class to catch our response. We have to name the variable with same name as JSON response with @SerializedName.

  • Add Interface

Add interface class to call our API call. Our interface looks like this.

  • Coding main java class

Now connect our android UI in this java class. Here we are displaying our response data.

That’s it guys now you can get data using retrofit library. If you have any query then please feel free to comment down below. Thank you.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.