“Bagaimana Mengonversi Kembali ke Json di PowerShell” Kode Jawaban

PowerShell mengonversi ke JSON

You could try some string manipulation to get it in an expected JSON format, and then use ConvertFrom-Json to convert it to a PSCustomObject.

Simple Example: (simple because this assumes that these characters being replaced will only be delimiters)

# First, clean up the string.
PS C:\> $mystring = "@{Account='User01';Domain='Domain01';Admin='True'}"
PS C:\> $mystring = $mystring -replace "^@", ""
PS C:\> $mystring = $mystring -replace "=", ":"
PS C:\> $mystring = $mystring -replace ";", ","
PS C:\> $mystring
{Account:'User01',Domain:'Domain01',Admin:'True'}

# Afterwards, convert to PSCustomObject.
PS C:\> $myobject = $mystring | ConvertFrom-Json
PS C:\> $myobject

Account                                 Domain                                  Admin
-------                                 ------                                  -----
User01                                  Domain01                                True
Ankur

Bagaimana Mengonversi Kembali ke Json di PowerShell

ConvertTo-Json -InputObject $my_object
Defiant Dog

Jawaban yang mirip dengan “Bagaimana Mengonversi Kembali ke Json di PowerShell”

Pertanyaan yang mirip dengan “Bagaimana Mengonversi Kembali ke Json di PowerShell”

Lebih banyak jawaban terkait untuk “Bagaimana Mengonversi Kembali ke Json di PowerShell” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya