开发者

Get object from GSON in Android

开发者 https://www.devze.com 2023-03-23 09:24 出处:网络
I have a situation here. May I know how to get json from \"place\" like in the example below through gson?

I have a situation here. May I know how to get json from "place" like in the example below through gson?

near.java:

public class near{
    private List<Place> place;
    private String type;

    public List<Place> getPlace(){
        return this.place;
    }
    public void setPlace(List<Place> place){
        this.place = place;
    }
    public String getType(){
        return this.ty开发者_运维技巧pe;
    }
    public void setType(String type){
        this.type = type;
    }
}

place.java:

public class Place{
       private String name;

   public String getname(){
       return this.name;
   }
   public void setname(String name){
       this.name = name;
   }
}

I know that to get TYPE in the NEAR class, it is

Gson json=new Gson();
near resultType =json.fromJson(result , near.class);

May I know how to get NAME in the PLACE class? Thanks..


How about:

resultType.getPlace().get(0).getname();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号