Retrieve data from Json through php in android?

后端 未结 3 893
梦如初夏
梦如初夏 2021-01-28 05:03

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\":\"         


        
相关标签:
3条回答
  • 2021-01-28 05:46

    if your responce is to big than @tiny sunlight method not work

    You cant do like

         JSONObject userinfo= new JSONObject(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

    Gson gson = new GsonBuilder().create();
    Movie movie = gson.fromJson(response, Movie.class);
    

    hear movie is class that you map from json - show in below link

    you can do vise-varsa also

    Gson gson = new GsonBuilder().create();
    Responce mResponce = gson.fromJson(jsonStr , Responce .class);
    String mName =mResponce.result.name;
    

    https://stackoverflow.com/a/41218155/4741746

    Hope you will understand which answer is best

    0 讨论(0)
  • 2021-01-28 05:49

    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!

    0 讨论(0)
  • 2021-01-28 06:07
     JSONObject userinfo= new JSONObject(result);
    
                userinfo.getString("first_name");
    

    Try to Use Gson to simplify it!

    0 讨论(0)
提交回复
热议问题