簡體   English   中英

如何使用 Powershell 從 URL 加載 JSON?

[英]how to use Powershell to load JSON from a URL?

如何獲取描述返回的 JSON 數據的元數據並將其加載到 object 中?

**********************
Transcript started, output file is jsonfu
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $request = 'http://musicbrainz.org/ws/2/recording/fcbcdc39-8851-4efc-a02a-ab0e13be224f?inc=artist-credits+isrcs+releases&fmt=json'
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $result = Invoke-WebRequest $request
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $result

StatusCode        : 200
StatusDescription : OK
Content           : {"releases":[{"id":"9c7a7669-b43a-3323-906b-c3f0bedc10c9","release-events":[{"date":"2007-11-07","area":{"type"
                    :null,"name":"Japan","disambiguation":"","iso-3166-1-codes":["JP"],"type-id":null,"sort-n…
RawContent        : HTTP/1.1 200 OK
                    Date: Thu, 17 Dec 2020 14:48:49 GMT
                    Connection: keep-alive
                    Keep-Alive: timeout=15
                    Vary: Accept-Encoding
                    X-RateLimit-Limit: 1200
                    X-RateLimit-Remaining: 749
                    X-RateLimit-Reset: 1608216530…
Headers           : {[Date, System.String[]], [Connection, System.String[]], [Keep-Alive, System.String[]], [Vary,
                    System.String[]]…}
Images            : {}
InputFields       : {}
Links             : {}
RawContentLength  : 4732
RelationLink      : {}


PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> exit
**********************
PowerShell transcript end
End time: 20201217064923
**********************

這是在解析本地存儲的 JSON 文件的上下文中。

這是在 Linux 上,所以不太確定什么可能不可用。

也可以看看:

遍歷 JSON 文件 PowerShell

這看起來,如果不是棘手的,那么至少不是微不足道的。

感謝 Jeroen mostert:

**********************
Transcript started, output file is jsonfu2
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $url = 'http://musicbrainz.org/ws/2/recording/fcbcdc39-8851-4efc-a02a-ab0e13be224f?inc=artist-credits+isrcs+releases&fmt=json'
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $response=Invoke-RestMethod -Url $url
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> TerminatingError(Invoke-RestMethod): "A parameter cannot be found that matches parameter name 'Url'."

Invoke-RestMethod: A parameter cannot be found that matches parameter name 'Url'.

Invoke-RestMethod: A parameter cannot be found that matches parameter name 'Url'.
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $response=Invoke-RestMethod
PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $response

releases       : {@{packaging=; title=LAST ANGEL; status=Official; id=9c7a7669-b43a-3323-906b-c3f0bedc10c9;
                 artist-credit=System.Object[]; date=2007-11-07; text-representation=;
                 status-id=4e304316-386d-3409-af2e-78857eec5cfe; packaging-id=; release-events=System.Object[];
                 barcode=4988064457663; quality=normal; country=JP; disambiguation=}, @{title=Kingdom; status=Official;
                 packaging=; id=56b1246a-7ff4-4183-b2f6-4e3f6cfacd05; date=2008-01-30; text-representation=;
                 artist-credit=System.Object[]; packaging-id=; status-id=4e304316-386d-3409-af2e-78857eec5cfe; quality=normal;
                 release-events=System.Object[]; barcode=; country=JP; disambiguation=}, @{packaging-id=;
                 status-id=4e304316-386d-3409-af2e-78857eec5cfe; date=2008-01-30; text-representation=;
                 artist-credit=System.Object[]; id=149aabbf-a54c-4156-a83b-47e0e1ab1069; status=Official; title=Kingdom;
                 packaging=; disambiguation=; country=JP; quality=normal; release-events=System.Object[]; barcode=}, @{country=KR;
                 disambiguation=; quality=normal; barcode=8809049753128; release-events=System.Object[]; text-representation=;
                 date=2008-01-31; artist-credit=System.Object[]; packaging-id=; status-id=4e304316-386d-3409-af2e-78857eec5cfe;
                 status=Official; title=Kingdom; packaging=; id=abcd76db-7d5f-3eb7-b386-051c97bfe2e4}…}
disambiguation : video
title          : LAST ANGEL
length         :
isrcs          : {}
id             : fcbcdc39-8851-4efc-a02a-ab0e13be224f
artist-credit  : {@{name=倖田來未; artist=; joinphrase= feat. }, @{artist=; name=東方神起; joinphrase=}}
video          : True


PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> $response | Get-Member

   TypeName: System.Management.Automation.PSCustomObject

Name           MemberType   Definition
----           ----------   ----------
Equals         Method       bool Equals(System.Object obj)
GetHashCode    Method       int GetHashCode()
GetType        Method       type GetType()
ToString       Method       string ToString()
artist-credit  NoteProperty Object[] artist-credit=System.Object[]
disambiguation NoteProperty string disambiguation=video
id             NoteProperty string id=fcbcdc39-8851-4efc-a02a-ab0e13be224f
isrcs          NoteProperty Object[] isrcs=System.Object[]
length         NoteProperty object length=null
releases       NoteProperty Object[] releases=System.Object[]
title          NoteProperty string title=LAST ANGEL
video          NoteProperty bool video=True

PS /home/nicholas/Desktop/takeout-20201215T221239Z-001/Takeout/Hangouts Chat/Groups/e> exit
**********************
PowerShell transcript end
End time: 20201217071644
**********************

雖然我不確定它是否完全描述了 JSON。

暫無
暫無

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

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