JSON.Net 始终返回 {}
Foo
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
Bar
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
My Form
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
我总是得到 {} 作为答案。怎么了?
Foo
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
Bar
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
My Form
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
I always get {} as answer. What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些类都没有任何
Public
属性或字段。如果您希望将字段表示为应出现在 JSON 字符串中的值,请将它们公开。否则,就序列化程序而言,您将为其提供没有有趣值的对象。Neither of these classes have any
Public
properties or fields. If you want to represent your fields as values that should be present in a JSON string, make them public. Otherwise, as far as the serializer is concerned, you're giving it objects with no interesting values on them.