Verwendung Folgende Abhängigkeit
<!-- json -->
<dependency>
<groupId>com.google.code.geocoder-java</groupId>
<artifactId>geocoder-java</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
Verwenden Sie folgenden Code in Ihrer Hauptmethode
public static void main(String[] args) {
try {
String point = "your json response";
Gson gson = new Gson();
TypeToken<RoutePlot> tokenPoint = new TypeToken<RoutePlot>() {
};
RoutePlot user = gson.fromJson(point, tokenPoint.getType());
System.out.println();
} catch (Exception e) {
e.printStackTrace();
}
}
Verwenden Sie nun die folgenden Klassen, die ich für die Antwort generiert habe, um sie in Java abzubilden
package com.admin.modules.restservices.google.pojo.routepojo;
public class Bounds {
private Northeast northeast;
private Southwest southwest;
public Northeast getNortheast() {
return northeast;
}
public void setNortheast(Northeast northeast) {
this.northeast = northeast;
}
public Southwest getSouthwest() {
return southwest;
}
public void setSouthwest(Southwest southwest) {
this.southwest = southwest;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Distance {
private String text;
private String value;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Duration {
private String text;
private String value;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Endlocation {
private String lat;
private String lng;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
import java.util.List;
public class Legs {
private Distance distance;
private Duration duration;
private String end_address;
private Endlocation end_location;
private String start_address;
private Startlocation start_location;
private List<Steps> steps;
private List<String> via_waypoint;
public List<String> getVia_waypoint() {
return via_waypoint;
}
public void setVia_waypoint(List<String> via_waypoint) {
this.via_waypoint = via_waypoint;
}
public Distance getDistance() {
return distance;
}
public void setDistance(Distance distance) {
this.distance = distance;
}
public Duration getDuration() {
return duration;
}
public void setDuration(Duration duration) {
this.duration = duration;
}
public String getEnd_address() {
return end_address;
}
public void setEnd_address(String end_address) {
this.end_address = end_address;
}
public Endlocation getEnd_location() {
return end_location;
}
public void setEnd_location(Endlocation end_location) {
this.end_location = end_location;
}
public String getStart_address() {
return start_address;
}
public void setStart_address(String start_address) {
this.start_address = start_address;
}
public Startlocation getStart_location() {
return start_location;
}
public void setStart_location(Startlocation start_location) {
this.start_location = start_location;
}
public List<Steps> getSteps() {
return steps;
}
public void setSteps(List<Steps> steps) {
this.steps = steps;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Northeast {
private String lat;
private String lng;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Overviewpolyline {
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Polyline {
private String points;
public String getPoints() {
return points;
}
public void setPoints(String points) {
this.points = points;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
import java.util.List;
public class RoutePlot {
private String status;
private List<Routes> routes;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<Routes> getRoutes() {
return routes;
}
public void setRoutes(List<Routes> routes) {
this.routes = routes;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
import java.util.List;
public class Routes {
private Bounds bounds;
private String copyrights;
private List<Legs> legs;
private Overviewpolyline overview_polyline;
private String summary;
private List<String> warnings;
private List<String> waypoint_order;
public Bounds getBounds() {
return bounds;
}
public void setBounds(Bounds bounds) {
this.bounds = bounds;
}
public String getCopyrights() {
return copyrights;
}
public void setCopyrights(String copyrights) {
this.copyrights = copyrights;
}
public List<Legs> getLegs() {
return legs;
}
public void setLegs(List<Legs> legs) {
this.legs = legs;
}
public Overviewpolyline getOverview_polyline() {
return overview_polyline;
}
public void setOverview_polyline(Overviewpolyline overview_polyline) {
this.overview_polyline = overview_polyline;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public List<String> getWarnings() {
return warnings;
}
public void setWarnings(List<String> warnings) {
this.warnings = warnings;
}
public List<String> getWaypoint_order() {
return waypoint_order;
}
public void setWaypoint_order(List<String> waypoint_order) {
this.waypoint_order = waypoint_order;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Southwest {
private String lat;
private String lng;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
public class Startlocation {
private String lat;
private String lng;
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
}
package com.admin.modules.restservices.google.pojo.routepojo;
import java.util.List;
public class Steps {
private Distance distance;
private Duration duration;
private Endlocation end_location;
private Startlocation start_location;
private String html_instructions;
private String travel_mode;
private Polyline polyline;
}