【问题标题】:Generating Class VB.NET生成类 VB.NET
【发布时间】:2017-08-21 13:05:50
【问题描述】:

我正在使用JSON Utils 生成一个类,但遇到了问题。我正在使用的 JSON 字符串:

{
  "type": "champion",
  "version": "7.16.1",
  "data": {
    "1": {
      "title": "the Dark Child",
      "id": 1,
      "key": "Annie",
      "name": "Annie"
    }
  }
}

它生成的类:

Public Class 1
    Public Property title As String
    Public Property id As Integer
    Public Property key As String
    Public Property name As String
End Class

Public Class Data
    Public Property 1 As 1
End Class

Public Class Example
    Public Property type As String
    Public Property version As String
    Public Property data As Data
End Class

问题是我无法命名 1 类,我仍在努力寻找解决方案,但还没有运气。有解决办法吗?

【问题讨论】:

  • 您不能命名以数字开头的对象。
  • @Karuntos 那是我的问题,但现在已经解决了。

标签: json vb.net


【解决方案1】:

我觉得应该改成Dictionary

Public Class Example
    Public Property type As String
    Public Property version As String
    Public Property data As Dictionary(Of String, NumberType)
End Class

Public Class NumberType
    Public Property title As String
    Public Property id As Integer
    Public Property key As String
    Public Property name As String
End Class

【讨论】:

  • 如果我在data: "1":"2": 中有另一个块,它会如何工作?
  • Yes ti 将创建带有两个键“1”和“2”的字典
  • 成功了!您不仅给了我一个简单的答案,还为我节省了将近 1k 行代码! (我的模型有 128 个数据块)谢谢!从现在开始我会记住字典的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-31
  • 2019-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多