Retrieve data from Json through php in android?

后端 未结 3 892
梦如初夏
梦如初夏 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

提交回复
热议问题