VB.NET newtonsoft列表

时间:2018-08-20 15:56:05

标签: vb.net json.net

简单的问题,但似乎找不到解决方案。 我有一个需要这样的json的json阅读器:

[
  {
    "name": "name",
    "ip": "0.0.0.0"
  },
  {
    "name": "name",
    "ip": "0.0.0.0"
  }
]

我在vb上这样创建了一个类:

Public Class main_object
            Public e As New List(Of _subObject)
            Public Class _subObject
                Public name As String
                Public ip As String
            End Class
        End Class

我的问题是输出以

开头
{
"e"[
mylist
]
}

有解决方案吗?

1 个答案:

答案 0 :(得分:2)

尝试一下:

Public Class _subObject
   Public name As String
   Public ip As String
End Class

dim e As New List(Of _subObject)
dim x as new _subObject
x.name = "name"
x.ip= "0.0.0.0"
e.add(x)
e.add(x)
Dim jsonString As String = JsonConvert.SerializeObject(e, Formatting.Indented)

您将在jsonString中得到它

[
  {
    "name": "name",
    "ip": "0.0.0.0"
  },
  {
    "name": "name",
    "ip": "0.0.0.0"
  }
]