如何将JSON更改为CSV? [英] How to change JSON to CSV?
本文介绍了如何将JSON更改为CSV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的代码
$username = "username"
$password = "password"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$response = Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Uri https://api.bitbucket.org/2.0/teams/Ateam/members -Method Get
$new = $response | select Values
$new.values = $new.values | ConvertTo-Json -Compress
$new.values
$csvinfo = (Get-Content $new.values | ConvertFrom-Json) |
Convertto-CSV -NoTypeInformation
$csvinfo | Export-Csv C:\Users\helloworld\Desktop\BitBucket\Ateam.team.csv -NoTypeInformation
@ $ new.values,
@$new.values,
我可以在屏幕上看到JSON文件,我想更改为CSV文件, / p>
I can see JSON file on my screen, I would like to change to CSV file, like above, I tried
$csvinfo = (Get-Content $new.values | ConvertFrom-Json) |
Convertto-CSV -NoTypeInformation
但它表示
Get-Content : Cannot find drive. A drive with the name '[{"username"' does not
exist.
At line:14 char:13
+ $csvinfo = (Get-Content $new.values | ConvertFrom-Json) | Convertto-CSV
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: ([{"username":String) [Get-Content], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetContentCommand
如何更改 $ new.values
到CSV和导出?
How can I change $new.values
to CSV and export?
我找到了答案
$csv = $new.values| ConvertFrom-JSON
$csv|Export-Csv C:\Users\helloworld\Desktop\BitBucket\ateam.team.csv -NoTypeInformation
推荐答案
添加此
。
$csv = $new.values| ConvertFrom-JSON
$csv|Export-Csv C:\Users\helloworld\Desktop\BitBucket\ateam.team.csv -NoTypeInformation
这篇关于如何将JSON更改为CSV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文