1

谁能提供一个使用java创建一个rest webservice来调用网站的api然后返回json的例子。

例如以下 URL 的 google maps API:

https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants+in+Sydney&sensor=true&key= {your_key}

会给我:

{
   "debug_info" : [],
   "html_attributions" : [
      "Listings by \u003ca href=\"http://www.yellowpages.com.au/\"\u003eYellow Pages\u003c/a\u003e"
   ],
   "next_page_token" : "CkQ2AAAAofX2E2QEjupf8_2fHdU2VWhd_m1UHQbfLZYt_Afh_pKBsboFKnChqjNnRAhabuNLATuCLqhDo43LaMpXFxDdGRIQFawAdzfVPVeUaD6p_vjjexoULA5HagnDRfChHbWdjDUkQYTTAsk",
   "results" : [
      {
         "formatted_address" : "2 Henry Lawson Avenue, McMahons Point NSW, Australia",
         "geometry" : {
            "location" : {
               "lat" : -33.848536,
               "lng" : 151.20613
            }
         },
         "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
         "id" : "518a9a070a33fb6e1ec75a076782515c688fd855",
         "name" : "Sails on Lavender Bay",
         "opening_hours" : {
            "open_now" : false
         },
         "photos" : [
            {
               "height" : 236,
               "html_attributions" : [],
               "photo_reference" : "CoQBfAAAABLadap32Q-C2R5MUp4RFdxYN5wIRzp1li8zyS_oqM0DZyjW5MJ5D5mzdSg_fUNrlnRpvZ2gYXSb8wGluXESztdKONUm4fqavwU7BdugbEYxyRqJmFkWnhNmEyNdj0WKHIYo4ViHWRUhnd3YgALSPBlnJBBTsBy8si9-5penG0LtEhBXI4Ijyq92xl762MwkDOCiGhQWEz49n1-5XplaLJ-PmuH8AeqpKQ",
               "width" : 371
            }
         ],
         "price_level" : 3,
         "rating" : 4.3,
         "reference" : "CoQBcwAAALMXTtQBHqX59XmtlsoyzeZRtxcmU7Tv9Dw70xypZNb10RcbsJH9ejaqx5I5HouifcbkaR60V7Xr4X1nmot9JJQW1IG2CHUXvGQCaLKPe2jHBLnwKuc79HmhE6qLl9Koh4xWzKtOqycGSTbU9-qeXqehGcRK2tlbY-DWaCnILqTeEhBGY3xdW3wFdQPD5VVEE3VYGhRYylVumuS7t3wmqJVkbplqW9pLJg",
         "types" : [ "restaurant", "food", "establishment" ]

其余 Web 服务应采用带有更改参数选项的 URL 并返回 JSON 结果

4

0 回答 0