Best Android Studio Tutorial: How to Parse JSON from URL

preview_player
Показать описание

Android Json Parsing Tutorial: How to Parse JSON from URL (Android Studio): In this video, I will teach how to do JSON Arrray Parsing in Android from URL of a website. Did you know there was no easy way to parse JSON from a URL into objects in Android? Originally we used JSONArray class to parse. Later Google released another lib called GSON. It was fairly useful and easy but you still needed to do a lot of code yourself, which consumed a lot of your time. Even worse, you needed to do the same thing over and over again from one project to another.

Please note that this tutorial may work on your older Samsung Galaxy, LG, Oppo, Huawei, Sony or Nokia Android phones which run Android Operating Systems depended on their API version.

To use that, first you add a model class that has its properties matching to JSON objects. For example, you have a tbl_post table and 4 attributes (post_id, post_title, post_text, image_url). Then by using json_encode() method in PHP, you should get the same object names in JSON. So, in Android you should create class named Post with 4 properties as well. See the sample code below:

public class Post {
@SerializedName("post_id ")
public int post_id;
@SerializedName("post_title")
public String post_title;
@SerializedName("post_text")
public String post_text;
@SerializedName("image_url")
public String image_url;
}

The SerializeName annotation is the keyword that helps your JSON objects properties match an Android objects properties. You have to make sure they are the same.

Finally, what you have to do is to call a one magic line of code:

JsonConverter

This code will parse the JSON text into objects. You can use that ArrayList for your custom ArrayAdapter to display texts and images in a ListView. But in this video, I make it simpler by just using a text list instead. Stay tuned for another awesome video about the custom ArrayAdapter.

Now, you are reaching the end of the Android JSON Parser from URL tutorial. Thanks for watching my video. Don't forget to subscribe for more videos. Like and share it to your friends.

If you want cool videos like this, you can follow me:

Oum Saokosal

Photo Credit:

The Creator of Channel Oum Saokosal
Android Json Parsing Tutorial
Рекомендации по теме
Комментарии
Автор

Good dear, you are first one to make a tutorial of app connect to web server...thanx alot

naumankhan
Автор

Thx you so much for this video thx thx htx so much

vynatlmin
Автор

That great videos, but what if we want to POST data from Android to server with parameter, header, or body. How to do it? Thank before hand for your response.

dotafreecoin
Автор

Thank you for the tutorial. Just want to ask, how do I pass the values to a text view instead of a list view.

goldendraco
Автор

It would be possible to use two "GetResponseAsyncTasks" in a script?
One to pick up the user data, and the other to pick up the posts?
I tried to use it, but when I put the two he does not think anything.
When I use only the first, it works taking regular user data. I tried to separate in other class, but without success.
I'm using Navigation Drawer.

thiagosalesdev
Автор

thanks for this worderful tuitorial!! can you have a crud operation using this?

jeraldjoemagno
Автор

If I had an activity, that gets the JSON Response from the PHP file, how do I put it in a bundle and pass it to some fragments? I think I can't use intent in passing Activity to Fragments.

marzgaming
Автор

How do you display it in a textview?
BTW. Your videos are Awesome !!!

sacyac
Автор

Thanks about this Tutorial. I've learned a lot. I just wanna ask.
I have an android app that should access 1 of 3 tables(3 types of users), and I wanted to pass the usertype and username to a php file, and retrieves the details of that username(assuming it's already logged in) from 1 of the 3 tables to a json array.
What should be the correct format for the URL to post/get the json array?

I apologize if I'm giving you a hard time.

UPDATE:

I already solved it, but I had to customize the link on task.execute(); for it to perform $_GET instead of $_POST. Again, thanks for this tutorial. :)

LorenzCal
Автор

Hi, Its really help full to me, but there is one problem to go far with this.
How we can manage if there are more then one items or data to show in list. suppose i have to show multiple students name, role number, class, marks etc in a list.
I got only students names list. i want to shoe role number, class and marks with each name.
What will be your recommendations ?

obsdig
Автор

Thanks for this library. But how can 'i use the PostResponseAsyncTask in a Fragment. Because i got a error (application stop) when trying to run the application. Thanks

weedees
Автор

Thanks for tutorial... There are an method by to store a variable in the system with the data: name, user, email ... after the user make the login with HASHMAP, and then catch the data and where do Gson for get the user data with "... WHERE User = 'User' "?

thiagosalesdev
Автор

how do i set id to textbox of perticular record return by web

vinayakchautre
Автор

Oum Saokosal Plz can you give us all the code source for this tutorial video

arrehadendoualeh
Автор

it says the PostResponseAsyncTask class is depreciated? it has a line going through it, and when i try to make a toast for the result, i get nothing. just a blank toast

hnbOFFICIAL
Автор

ThankQ very much sir ..but i want checkbok along with name how can i get that sir

temperdamodarchowdary
Автор

Which one sir daily I'm searching for that and in this video we are assigning data to list view .How to assign to Autocompletetextview please help me sis

temperdamodarchowdary
Автор

Hello. I tried to follow through your tutorial but I'm having this error -> "Expected BEGIN_OBJECT but was STRING". What is the solution to this problem?

jaspermendiola
Автор

how bout doing it on a textview is it possible?

jaykahano
Автор

hi sir, i want all the names, how i can get all the names as a list view with checkbox please help me sir

temperdamodarchowdary
welcome to shbcf.ru