创建RESTful Web服务并调用API,GET json

时间:2013-08-23 14:16:47

标签: web-services rest

任何人都可以提供一个使用java创建休息Web服务的示例来调用网站的api,然后返回json。

例如,以下网址的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结果

0 个答案:

没有答案