Javatpoint Logo
Javatpoint Logo

Kotlin Android JSON Parsing using URL

JSON refers to JavaScript Object Notation, and it is a programming language. JSON is used to parse the data between the server and the client. It is minimal, textual and a subset of JavaScript. It is the alternative to XML parsing.

The advantage of JSON over XML

  1. JSON is faster and easier than XML for AJAX applications.
  2. Unlike XML, it is shorter and quicker to read and write.
  3. It uses an array.

JSON Object

A JSON object contains key/value pairs like a map. The keys are strings and the values are the JSON types. A comma separates keys and values (,). The curly brace {} represents the JSON object.

Kotlin JSON Parsing using URL Example

In this example, we parse the JSON data from URL and bind them into a ListView. The JSON data contains the "id" "name" "email".

JSON data index.html

Create a JSON file index.html.

While executing the JSON file (index.html) looks like as:

Kotlin Android JSON Parsing using URL


Add the ListView in the activity_main.xml layout file.


Add the following okhttp dependency in the build.gradle file.


Create a data model class Model.kt which includes the information String "id", String "name" and String "email".


Create an adapter_layout.xml file in the layout directory which contains the row items for ListView.


Create a custom adapter class CustomAdapter.kt and extend BaseAdapter to handle the custom ListView.


Add the following code in MainActivity.kt class file. This class read the JSON data in the form of a JSON object. Using the JSON object, we read the JSON array data. The JSON data are bind in ArrayList.


Add the Internet permission in AndroidManifest.xml file.


Kotlin Android JSON Parsing using URL

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA