我在文件中有JSON原始内容。我正在尝试使用ConvertFrom-Json解析网址。不知怎的,它不起作用。我们非常感谢您的想法。
$file1 = "C:\Test\output1.txt"
$file2 = "C:\Test\output2.txt"
$content = Get-Content $file1
$response = ConvertFrom-Json $content
$urls = $response.input | where {$_.url}
$urls | Out-File $file2
output1文件中的原始内容为:
{"workitems":[{"Inputs":{"url":"http://www.cmha.ca/news-and-events/news/?70301308070201301010","c":"1"},"Outputs":{"ip":"50.56.166.145","latencymilliseconds":"785","httpstatuscode":"200","completeresponse":"HTTP/1.1 200 OK\r\nVary: ......etc}}]}
该文件的大小约为10K KB。我们如何最好地解析并获取Urls到output2.txt文件?
答案 0 :(得分:0)
运行以下代码
$file1 = "file1.txt"
$content = Get-Content $file1
$response = ConvertFrom-JSON $content
$urls = $response.workitems.inputs | where {$_.url}
$urls.url
<强>输出强>
http://www.cmha.ca/news-and-events/news/?70301308070201301010