Understanding JSON and using GSON in Android with Kotlin and Android Studio

Описание к видео Understanding JSON and using GSON in Android with Kotlin and Android Studio

🚀 Android & Kotlin Masterclass - Become a serious Android app developer with our best-selling masterclass: https://bit.ly/3PaKdhS

In this video you will learn what JSON is and how to use GSON in Android Studio.

You can find the article with the code here: https://tutorials.eu/json-parsing-and...
Stay tuned and subscribe to tutorialsEU: https://goo.gl/rBFh3x

The sharing of data over the Internet is a prevalent task. Nowadays, almost every application has some features to exchange the data with the server over the Internet.

The details send and receive from the server can be in XML or JSON format. When you want to use the data store using these file formats in the database, you must apply some parsing of data in your Android Application. For the JSON file, you have to use the JSON parsing, and for XML files, you can use the XML parsing. In this article, you will learn how to parse the JSON format data and use it in our Android Application. So, let’s get started with JSON parsing.

What is JSON?

JSON stands for JavaScript Object Notation. The JSON is used to exchange the data from the server to the desired place over the Internet. The XML parsing is more complicated as compared to JSON parsing.

JSON is structured, lightweight, and an independent data exchange format used to parse data. JSON is also language-independent. JSON uses the syntax of JavaScript, which is limited to text. Apart from this, nowadays, most of the APIs available to us is sending data in the form of JSON and receiving that data from API, you have to do JSON parsing, and it is straightforward to do JSON parsing.

To manipulate JSON data and to play with JSON, Android provides four classes. These classes are:

JSONObject
JSONArray
JSONStringer
JSONTokenizer
JSON Structure

JSON uses two types of brackets which are as below:

[] – JSON uses square brackets to declare an Array's elements in JSON.
{} – JSON uses the curly brackets to create JSON objects elements.

JSON has the following types of structures that generally used, which are as below:

JSON Array

The elements present the list of values in the ([...]), known as Arrays. Inside the JSON array, you can put values like Integer, Boolean, String, Float, and also you can put some other JSON array or JSON object in a particular JSON array. 

JSON Objects

The elements present inside the curly ({...}) brackets are known as Objects. The JSON object contains key/value pairs like the Hash map. In the JSON object, we can also use nested JSONObjects, which are very commonly used nowadays. 

JSON Key-Value

The values can be in any primitive data type and are the value corresponding to a particular key. For example: "Username":"Denis Panjuta". Here the Username is key and the value corresponding is "Denis Panjuta".

JSON Parsing Functions

This is a list of functions in android which can be used for JSON Parsing:

get(int index): It is used to get the value of the object type present in the JSON array. It throws an exception if there is no JSONObject in the JSON array.
getType(int index): It gets the value of any of the mentioned types present in the JSON array. The type can be String, Int, Boolean, Long, Double, JSONArray, or JSONObject. 
length(): It is used to get the length of the array.
opt(int index): It returns the Object Type value in the JSONArray on a particular index.
optType(int index ): It returns the value of the mentioned types in the JSONArray on a particular index.
JSON Parsing in Android

You have learned the concept of JSON Parsing and its functions. Now, let’s implement the concept in the android project.

Parse the JSON using GSON

Now, you have seen the JSON parsing with the functions and which we need to do it manually line by line.

Here I will show you how to do it with a third-party library. There are many libraries that are used to parse JSON objects with the help of the data model class.

I will show you the third party library GSON which is quite popular. You can check out the link for more details.

Add the below dependency to your app-level build.gradle file to use GSON.

implementation 'com.google.code.gson:gson:2.8.6'

Alright. Now you understand what JSON is and how you can use GSON in order to save loads of time when working with JSON.

This video is about:
- JSON in Android
- JSON in Android Studio Tutorial
- Using JSON in Android Studio
And of course, using GSON in android studio
parsing JSON using GSON
GSON tutorial Kotlin
GSON tutorial Android
You will see how to use GSON in android studio.
You will learn the basics of JSON
And how to parse JSON in android studio
also how to parse JSON using GSON in android
and of course how to parse JSON using GSON
So you will learn all the Parsing basics in android studio
This is a JSON tutorial for beginners which will cover JSON fundamentals in Kotlin

Комментарии

Информация по комментариям в разработке