我有一个方法将对象序列化为json格式。该对象包含嵌套对象和列表。但我面对这个错误:
从'长度'获取价值时出错on' Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter'。
Dim serilaize As New JsonSerializerSettings()
With serilaize
.PreserveReferencesHandling = PreserveReferencesHandling.Objects
End With
Dim strProgram As String = JsonConvert.SerializeObject(ProgramObject, Formatting.Indented, serilaize)
请帮忙! 感谢
答案 0 :(得分:0)
这有效:
Module Module1
Sub Main()
Dim ProgramObject = New TestObject()
ProgramObject.Items = New List(Of String)
ProgramObject.Items.Add("testitem")
Dim serialize As New Newtonsoft.Json.JsonSerializerSettings()
With serialize.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects
Dim strProgram As String = Newtonsoft.Json.JsonConvert.SerializeObject(ProgramObject, Newtonsoft.Json.Formatting.Indented, serialize)
End With
End Sub
End Module
TestObject如下所示:
Public Class TestObject
Property Items As List(Of String)
End Class