“PowerShell mengonversi ke JSON” 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 “PowerShell mengonversi ke JSON”

Pertanyaan yang mirip dengan “PowerShell mengonversi ke JSON”

Lebih banyak jawaban terkait untuk “PowerShell mengonversi ke JSON” di Shell/Bash

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya