WebServicesÖÐʹÓÃJSON
3 3ÔÂ, 2015 ÔÚ PowershellС¼¼ÇÉ tagged Web / Web·þÎñ by codecook
ÊÊÓÃÓÚPS3.0¼°ÒÔºó°æ±¾¡£
ÕâÀï¿ÉÒÔÓÃJSON¸ñʽ´ÓÍøÉϵõ½´óÁ¿µÄÐÅÏ¢£¬ÏÂÃæÀý×ÓÑÝʾÈçºÎ½«ÍøÉϲ鵽µÄ½á¹ûת»»³ÉJSON¶ÔÏó¡£
Õâ¸öÀý×ÓʹÓÃÁËÒ»¸öµÂ¹úÌú·¹«Ë¾µÄÍøÕ¾£¬Äã¿ÉÒÔÊäÈëÒ»¸ö»ð³µÕ¾µÄÃû×Ö»ò³ÇÊУ¬Ëû½«·µ»ØÄãÏëҪȥµÄÀàËÆËùÓгµÕ¾Ãû³Æ¡£
# ask for part of the train station name $name = Read-Host 'Enter part of train station Name' # query webservice $url = "http://openbahnapi.appspot.com/rest/stations/list?contains=$name" $site = Invoke-WebRequest -Uri $url # get JSON result ($site.Content | ConvertFrom-Json ).valueÕâ¸ö½á¹ûÀàËÆÈçÏ£º
PS> Enter part of train station name: hanno Hannover Hbf HANNOVER MESSE Hannoversch M¨¹nden Hannover-Nordstadt Hannover Bismarckstr. Hannover Karl-Wiechert-Allee Hannover-Ledeburg Hannover-Linden/Fischerhof Hannover-Vinnhorst Hannover-Leinhausen Hannover Anderten-Misburg Hannover-Bornum PS>Õâ¸öÀý×Ó²»ÊÇÒª½ÌÄãÈ¥²éѯµÂ¹úÌú·£¬ËùÒÔÈç¹ûÄã¶Ô´Ë²»¸ÐÐËȤ£¬¿ÉÒÔÐ޸ijɱðµÄÓ¦Óãº
Invoke-WebRequestÊÇÒ»¸öÖØÒª²¿·Ö£¬Ëü°üº¬Web·þÎñ·µ»ØµÄ½á¹û£»Í¬Ê±ConvertFrom-Json Ò²Ï൱ÖØÒª£¬Ëü¿ÉÒÔ½«½á¹ûת»¯³É¶ÔÏó¡£
×¢ÒâWeb·þÎñµÄ´¦Àí±ä»¯£¬ÕâÀïÖ»ÊÇÒ»¸öÓÃÀý¡£
ÔÎĵØÖ·£º
±¾ÎÄÁ´½Ó£º
Çë×ðÖØÔ×÷Õߺͱ༵ÄÐÁÇÚÀͶ¯,»¶ÓתÔØ,²¢×¢Ã÷³ö´¦!
Ïà¹ØÎÄÕÂÍƼö£º
¹ØÓÚ codecook
¼ÓÓÍ¡£
²Î¿´ËùÓÐÎÄÕ codecook →
Leave a comment
ÎÄÕµ¼º½
¡¡