简体   繁体   English

Spring Boot + Jersey解析响应JSON数据

[英]Spring boot + Jersey parse Response JSON data

I am trying to build a simple page the will display some places on the map. 我正在尝试构建一个简单的页面,该页面将在地图上显示一些位置。 I'm really new to rest in Java and i'm using Spring boot + jersey framework. 我真的是Java的新手,我正在使用Spring boot + jersey框架。

I'm using google places api to search for places, i made the GET respond for a lat/lng that i'm passing thru PostMan: 我正在使用Google Places api搜索地方,我让GET响应了我通过PostMan传递的经纬度:

http://localhost:9000/res/-23.558712/-46.592235

Inside the code im calling: 在代码内部调用:

@GET
@Path("/{lat}/{lng}")
@Produces("application/json")
public void getBook(@PathParam("lat") String lat,@PathParam("lng") String lng) {
    this.lat = lat;
    this.lng = lng;
    getdata();
}
public static void getdata(){
    Client client = ClientBuilder.newClient();
    String entity = client.target("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="+ lat + "," + lng + "&radius=5000&types=market&name=dia&key=MY_KEY")
            .request(MediaType.TEXT_PLAIN_TYPE)
            .header("some-header", "true")
            .get(String.class);
    System.out.println(entity);
}

And i get a really big Json in the response: 我得到了一个很大的Json:

"results" : [
  {
     "geometry" : {
        "location" : {
           "lat" : -23.5703071,
           "lng" : -46.58153289999999
        },
        "viewport" : {
           "northeast" : {
              "lat" : -23.56895811970849,
              "lng" : -46.5801839197085
           },
           "southwest" : {
              "lat" : -23.5716560802915,
              "lng" : -46.58288188029149
           }
        }
     },....

And much more, my question is, how do i parse this JSON response to away that i can manage data? 还有,我的问题是,如何解析此JSON响应以使我可以管理数据? I want to get, name, location... to plot on the map. 我想获取名称,位置...以在地图上绘制。 I will have to create a model class with all response parameters? 我将不得不创建一个具有所有响应参数的模型类吗?

I really don't know if this is all wrong. 我真的不知道这是否全都错了。

This resource falls under reverse geocoding and if you need name of the location you should get it from "fromatted_address" attiribute, and address components will give you exact address. 此资源属于反向地理编码,如果您需要位置名称,则应从“ fromatted_address”属性中获取,地址组件将为您提供确切的地址。 The following link has some information which might help you further. 以下链接包含一些信息,可能会进一步帮助您。 [reverse geocoding] https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding [反向地理编码] https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM