簡體   English   中英

Spring Boot + Jersey解析響應JSON數據

[英]Spring boot + Jersey parse Response JSON data

我正在嘗試構建一個簡單的頁面,該頁面將在地圖上顯示一些位置。 我真的是Java的新手,我正在使用Spring boot + jersey框架。

我正在使用Google Places api搜索地方,我讓GET響應了我通過PostMan傳遞的經緯度:

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

在代碼內部調用:

@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);
}

我得到了一個很大的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
           }
        }
     },....

還有,我的問題是,如何解析此JSON響應以使我可以管理數據? 我想獲取名稱,位置...以在地圖上繪制。 我將不得不創建一個具有所有響應參數的模型類嗎?

我真的不知道這是否全都錯了。

此資源屬於反向地理編碼,如果您需要位置名稱,則應從“ fromatted_address”屬性中獲取,地址組件將為您提供確切的地址。 以下鏈接包含一些信息,可能會進一步幫助您。 [反向地理編碼] https://developers.google.com/maps/documentation/geocoding/intro#ReverseGeocoding

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM