Retrieve Data From Json Through Php In Android?
I have the following data in Json how could I retrieve data from this file {'first_name':'immi','last_name':'Ahmad','contact_no':'0333333','dob':'2010-09-29','gender':'Male','pro_i
Solution 1:
if your responce is to big than @tiny sunlight method not work
You cant do like
JSONObject userinfo= newJSONObject(result);
userinfo.getString("first_name");
JSONObject someObject = userinfo.getJsonObject("somthing")
JSONObject somthingElse = someObject.getJsonObject("somthingElse")
That become too hectic and nearly wasting your time
So BEST ANSWER is Gson Liabrary
Gsongson=newGsonBuilder().create();
Moviemovie= gson.fromJson(response, Movie.class);
hear movie is class that you map from json - show in below link
you can do vise-varsa also
Gsongson=newGsonBuilder().create();
ResponcemResponce= gson.fromJson(jsonStr , Responce .class);
StringmName=mResponce.result.name;
https://stackoverflow.com/a/41218155/4741746
Hope you will understand which answer is best
Solution 2:
JSONObject userinfo= newJSONObject(result);
userinfo.getString("first_name");
Try to Use Gson
to simplify it!
Solution 3:
That's your all the content of json file?
You should create a class to store the information of every json object.
example you create PersonalInformation class have have instances "firstname", "lastname", "gender"...
Then we use a for-loop statement to read all information.
Hope this help!
Post a Comment for "Retrieve Data From Json Through Php In Android?"