N
N
newdancer2016-07-19 20:39:54
Android
newdancer, 2016-07-19 20:39:54

How to correctly write a model for Retrofit2 and get data?

How to correctly write a model for Retrofit2 and get data?
Here is the api:

http://maps.googleapis.com/maps/api/geocode/json?address=Москва,%20город%20Москва,%20Россия&sensor=false

Of all these data, I only need location data lat and lng. I wrote a data fetch model
public class GeoModel
{
  @Expose
  private List<Results> results;
  @Expose
  private List<Geometry> geometry;

  public List<Results> getResults() {
    return results;
  }

  public int getRezUpdates() {
    return results.size();
  }

  public class Results
  {
    @SerializedName("geometry")
    private String geometry;

    public String getGeometry() {
      return geometry;
    }
  }

  public class Geometry
  {
    @SerializedName("geometryData")
    private String geometryData;

    public String getGeometryData() {
      return geometryData;
    }
  }
}

I know how to get the results data, but I don’t know how to further pull out the data I need?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mitekgrishkin, 2016-07-19
@newdancer

Given the given json

"geometry" : {
            "bounds" : {
               ...
            },
            "location" : {
               "lat" : 55.755826,
               "lng" : 37.6173
            },
    ...

I would write the bottom part of the code like this
public class Geometry
  {
     private Location location;
     //геттер,сеттер
  }

class Location {
  private String lat;
  private String lng;
     //геттеры,сеттеры
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question