I have a problem using PowerShell v3 when converting JSON strings over 2MB in size. The default limit in JSON serializer used by PowerShell is set to 2MB which explains the error.
However when I deserialize object using ConvertFrom-Json on a smaller set (I got various data objects with smaller and bigger internal collections but those are the same objects) it returns very nice object with all properties which I can easily access.
To overcome the limitations of the serializer I tried to deserialize data by hand:
$jsser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$jsser.MaxJsonLength = $jsser.MaxJsonLength * 10
$jsser.RecursionLimit = 99
$outObject = $jsser.DeserializeObject($json)
The object looks differently it seems that internal collections were not deserialized and when I try to execute properties they return empty results.
My questions:
Assumption is ConvertFrom-Json
does some additional magic or somehow creates a template for the object before serialization. Any idea how to replicate it?
The object I get is always a PSCustomObject
; if I get the object I want setup by ConvertFrom-Json
is there anyway to use it as object type in JsonSerializer?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…