我有一个像这样的json文件: {“跳过”:0, “拿”:100, “行”:[ { “WG”:“1013”, “Werkgever”:“1013”, “曹”:“0000” } ]}
现在我需要使用powerhsell
将此转换为csv文件"WG","Werkgever","Cao"
"1013","1013","0000"
脚本是:
Get-Content -Raw $file |
ConvertFrom-Json |
select @{n='WG';e={$_.WG | select -Expand WG}},
@{n='Werkgever';e={$_.Werkgever | select -Expand Werkgever}},
@{n='Cao';e={$_.Cao| select -Expand Cao}}|
Export-Csv $FileName1 -NoType
只有我错过了价值...... 它出来像:
"WG","Werkgever","Cao"
"","",""
我做错了什么?
答案 0 :(得分:1)
只需使用rows属性导出数据
$content = Get-Content -Raw $file | ConvertFrom-Json
$content.rows | export-csv 'somepath' -NoTypeInformation
答案 1 :(得分:0)
试试这个
get-content "C:\temp\test.txt" | ConvertFrom-Json | % {$_.Rows} | export-csv "C:\temp\test2.txt" -NoType