[英]Convert JSON to plist use PowerShell
convert JSON to plist have many ways, The most convenient is to use commands under the apple system, or to use online generation tools, But PowerShell does not provide direct commands, I found a project in GitHub, which can be easily converted for simple JSON ,但是對於一些稍微復雜的JSON,轉換后會出現一些問題
項目地址: https://github.com/msftrncs/PwshJSONtoPList
存在的問題:
某些 arrays 未正確轉換
我錄制了一個視頻演示https://www57.zippyshare.com/v/krihd4Y8/file.html
相關文件https://www57.zippyshare.com/v/84wYYTRx/file.html
powershell 腳本代碼:
. '.\ConvertTo-PList.ps1' # Put ConvertTo-PList.ps1 in the same directory
Get-Content "test.json" | ConvertFrom-Json |
ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' |
Set-Content 'Generated.plist' -Encoding 'UTF8'
測試.json:
{
"ACPI": {
"DSDT": {
"Debug": false,
"DropOEM_DSM": false,
"Fixes": {
"AddDTGP": false,
"FixHPET": false,
"FixRTC": false,
"FixShutdown": false
},
"Patches": [
{
"Comment": "change SAT0 to SATA",
"Disabled": false,
"Find": "U0FUMA==",
"Replace": "U0FUQQ=="
},
{
"Comment": "change HECI to IMEI",
"Disabled": false,
"Find": "SEVDSQ==",
"Replace": "SU1FSQ=="
}
],
"ReuseFFFF": false
},
"DropTables": [
{
"Signature": "DMAR"
},
{
"Signature": "MATS"
}
],
"FixHeaders": true,
"SSDT": {
"DropOem": false,
"Generate": {
"CStates": true,
"PStates": true
}
}
},
"GUI": {
"Custom": {
"Entries": [
{
"Disabled": false,
"FullTitle": "MAC OS X",
"Hidden": false,
"InjectKexts": true,
"NoCaches": true,
"Type": "OSX",
"Volume": "2D4A5E3A-04FC-3041-471B-8A1622089D19"
},
{
"Disabled": false,
"FullTitle": "WIN",
"Hidden": false,
"Type": "Windows",
"Volume": "2BDB20A2-1E67-4AE2-753D-D85E9A410000"
}
]
},
"Hide": [
"Preboot",
"Recovery",
"BOOTX64.EFI",
"DATA"
]
},
"KernelAndKextPatches": {
"ForceKextsToLoad": [
"\\System\\Library\\Extensions\\IONetworkingFamily.kext"
],
"KextsToPatch": [
{
"Comment": "External icons patch",
"Disabled": false,
"Find": "RXh0ZXJuYWw=",
"InfoPlistPatch": false,
"Name": "AppleAHCIPort",
"Replace": "SW50ZXJuYWw="
},
{
"Comment": "Enable TRIM for SSD",
"Disabled": false,
"Find": "AEFQUExFIFNTRAA=",
"InfoPlistPatch": false,
"Name": "com.apple.iokit.IOAHCIBlockStorage",
"Replace": "AAAAAAAAAAAAAAA="
}
]
}
}
生成的.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ACPI</key>
<dict>
<key>DSDT</key>
<dict>
<key>Debug</key>
<false/>
<key>DropOEM_DSM</key>
<false/>
<key>Fixes</key>
<string>@{AddDTGP=False; FixHPET=False; FixRTC=False; FixShutdown=False}</string>
<key>Patches</key>
<string> </string>
<key>ReuseFFFF</key>
<false/>
</dict>
<key>DropTables</key>
<array>
<string>@{Signature=DMAR}</string>
<string>@{Signature=MATS}</string>
</array>
<key>FixHeaders</key>
<true/>
<key>SSDT</key>
<dict>
<key>DropOem</key>
<false/>
<key>Generate</key>
<string>@{CStates=True; PStates=True}</string>
</dict>
</dict>
<key>GUI</key>
<dict>
<key>Custom</key>
<dict>
<key>Entries</key>
<string> </string>
</dict>
<key>Hide</key>
<array>
<string>Preboot</string>
<string>Recovery</string>
<string>BOOTX64.EFI</string>
<string>DATA</string>
</array>
</dict>
<key>KernelAndKextPatches</key>
<dict>
<key>ForceKextsToLoad</key>
<array>
<string>\System\Library\Extensions\IONetworkingFamily.kext</string>
</array>
<key>KextsToPatch</key>
<array>
<string>@{Comment=External icons patch; Disabled=False; Find=RXh0ZXJuYWw=; InfoPlistPatch=False; Name=AppleAHCIPort; Replace=SW50ZXJuYWw=}</string>
<string>@{Comment=Enable TRIM for SSD; Disabled=False; Find=AEFQUExFIFNTRAA=; InfoPlistPatch=False; Name=com.apple.iokit.IOAHCIBlockStorage; Replace=AAAAAAAAAAAAAAA=}</string>
</array>
</dict>
</dict>
</plist>
我在這里看到的版本也有一個-Depth
參數。
如果我在您的 json 上使用它並將深度設置為 4(或更高)
$json | ConvertFrom-Json | ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' -Depth 4
它產生這個:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ACPI</key>
<dict>
<key>DSDT</key>
<dict>
<key>Debug</key>
<false/>
<key>DropOEM_DSM</key>
<false/>
<key>Fixes</key>
<dict>
<key>AddDTGP</key>
<false/>
<key>FixHPET</key>
<false/>
<key>FixRTC</key>
<false/>
<key>FixShutdown</key>
<false/>
</dict>
<key>Patches</key>
<array>
<dict>
<key>Comment</key>
<string>change SAT0 to SATA</string>
<key>Disabled</key>
<false/>
<key>Find</key>
<string>U0FUMA==</string>
<key>Replace</key>
<string>U0FUQQ==</string>
</dict>
<dict>
<key>Comment</key>
<string>change HECI to IMEI</string>
<key>Disabled</key>
<false/>
<key>Find</key>
<string>SEVDSQ==</string>
<key>Replace</key>
<string>SU1FSQ==</string>
</dict>
</array>
<key>ReuseFFFF</key>
<false/>
</dict>
<key>DropTables</key>
<array>
<dict>
<key>Signature</key>
<string>DMAR</string>
</dict>
<dict>
<key>Signature</key>
<string>MATS</string>
</dict>
</array>
<key>FixHeaders</key>
<true/>
<key>SSDT</key>
<dict>
<key>DropOem</key>
<false/>
<key>Generate</key>
<dict>
<key>CStates</key>
<true/>
<key>PStates</key>
<true/>
</dict>
</dict>
</dict>
<key>GUI</key>
<dict>
<key>Custom</key>
<dict>
<key>Entries</key>
<array>
<dict>
<key>Disabled</key>
<false/>
<key>FullTitle</key>
<string>MAC OS X</string>
<key>Hidden</key>
<false/>
<key>InjectKexts</key>
<true/>
<key>NoCaches</key>
<true/>
<key>Type</key>
<string>OSX</string>
<key>Volume</key>
<string>2D4A5E3A-04FC-3041-471B-8A1622089D19</string>
</dict>
<dict>
<key>Disabled</key>
<false/>
<key>FullTitle</key>
<string>WIN</string>
<key>Hidden</key>
<false/>
<key>Type</key>
<string>Windows</string>
<key>Volume</key>
<string>2BDB20A2-1E67-4AE2-753D-D85E9A410000</string>
</dict>
</array>
</dict>
<key>Hide</key>
<array>
<string>Preboot</string>
<string>Recovery</string>
<string>BOOTX64.EFI</string>
<string>DATA</string>
</array>
</dict>
<key>KernelAndKextPatches</key>
<dict>
<key>ForceKextsToLoad</key>
<array>
<string>\System\Library\Extensions\IONetworkingFamily.kext</string>
</array>
<key>KextsToPatch</key>
<array>
<dict>
<key>Comment</key>
<string>External icons patch</string>
<key>Disabled</key>
<false/>
<key>Find</key>
<string>RXh0ZXJuYWw=</string>
<key>InfoPlistPatch</key>
<false/>
<key>Name</key>
<string>AppleAHCIPort</string>
<key>Replace</key>
<string>SW50ZXJuYWw=</string>
</dict>
<dict>
<key>Comment</key>
<string>Enable TRIM for SSD</string>
<key>Disabled</key>
<false/>
<key>Find</key>
<string>AEFQUExFIFNTRAA=</string>
<key>InfoPlistPatch</key>
<false/>
<key>Name</key>
<string>com.apple.iokit.IOAHCIBlockStorage</string>
<key>Replace</key>
<string>AAAAAAAAAAAAAAA=</string>
</dict>
</array>
</dict>
</dict>
</plist>
顯然你有一個舊版本的腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.