富
Public Class Foo
Private fooz As Object
Private alao As ArrayList
Public Sub New(ByVal pfooz)
Me.fooz = New Object
Me.alao = New ArrayList()
Me.alao.Add(1)
Me.alao.Add(2)
Me.alao.Add(3)
Me.alao.Add(4)
Me.alao.Add(5)
End Sub
End Class
酒吧
Public Class Bar
Private baz As Integer
Private bar As String
Private foo As Foo
Public Sub New(ByVal pbaz, ByVal pbar, ByVal pfoo)
Me.baz = pbaz
Me.bar = pbar
Me.foo = pfoo
End Sub
End Class
我的表格
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim foo As Foo = New Foo(New Object)
Dim bar As Bar = New Bar(1, "FOOOOOOOOOOOOO, bar?", foo)
Dim fooString As String
Dim barString As String
fooString = Newtonsoft.Json.JsonConvert.SerializeObject(foo)
barString = Newtonsoft.Json.JsonConvert.SerializeObject(bar)
MsgBox(fooString)
MsgBox(barString)
End Sub
End Class
我总是得到{}作为答案。怎么了?
答案 0 :(得分:2)
这些类都没有任何Public
属性或字段。如果要将字段表示为应存在于JSON字符串中的值,请将其公开。否则,就序列化器而言,你给它的对象没有任何有趣的值。