YAML文件中的嵌套列表-在VB.net中创建类时遇到问题(eve-online SDE)



我对YAML格式和VB.net很陌生(在VB6工作了大约5年并迁移过来,这个项目有点学习(。我也在使用yamldotnet软件包。

目前,我正在修改一些代码,这些代码是为了解析Eve Online SDE中的.yaml文件而发布的,因为SDE已经向yaml文件添加了新字段。理想情况下,我希望在调用API时使用此文件,以便从SDE文件中获取静态信息。

我一直在为"masteries"字段的"临时"类添加属性。我已经编辑了en/de/fr/等。描述以便于阅读。

582:
capacity: 270.0
description:
de: info
en: info
fr: info
ja: info
ru: info
zh: info
factionID: 500001
graphicID: 38
groupID: 25
marketGroupID: 61
mass: 1480000.0
masteries:
0:
- 96
- 139
- 85
- 87
- 94
1:
- 96
- 139
- 85
- 87
- 94
2:
- 96
- 139
- 85
- 87
- 94
3:
- 96
- 139
- 85
- 87
- 94
4:
- 96
- 139
- 85
- 118
- 87
- 94
name:
de: Bantam
en: Bantam
fr: Bantam
ja: バンタム
ru: Bantam
zh: 矮脚鸡级
portionSize: 1
published: true
raceID: 1
radius: 27.0
sofFactionName: caldaribase
soundID: 20070
traits:
roleBonuses:
-   bonus: 300
bonusText:
de: info
en: info
fr: info
ja: info
ru: info
zh: info
importance: 1
unitID: 105
types:
3330:
-   bonus: 10
bonusText:
de: info
en: info
fr: info
ja: info
ru: info
zh: info
importance: 1
unitID: 105
-   bonus: 10
bonusText:
de: info
en: info
fr: info
ja: info
ru: info
zh: info
importance: 2
unitID: 105
volume: 20000.0

我所拥有的类,到目前为止,我一直在添加属性作为

Class YAMLtempItem
Public Property basePrice As Decimal?
Public Property description As Dictionary(Of String, String)
Public Property groupID As Integer
Public Property iconID As Integer?
Public Property marketGroupID As Integer?
Public Property mass As String
Public Property name As Dictionary(Of String, String)
Public Property portionSize As Integer
Public Property published As Boolean
Public Property volume As Decimal?
Public Property radius As Double?
Public Property graphicID As Integer?
Public Property soundID As Integer?
Public Property raceID As Integer?
Public Property sofFactionName As String
Public Property capacity As String
Public Property factionID As Integer?
Public Property masteries As Dictionary(Of List(Of Integer), Integer)
End Class

调用解析的代码如下。目前,它只是点击一个按钮来启动解析过程,因为这最终将成为一个添加到更大应用程序中的模块。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Dim input = New StringReader("C:....typeIDs.yaml")
Dim input = System.IO.File.ReadAllText("C:UsersahooksDropboxEve VB.net ProjectsEVE ResourcesStatic Data YAMLtypeIDs.yaml")
TextBox3.Text = ""
Dim deserializer = New Deserializer()
Dim strtemp = New StringReader(input)
Dim itemTypes = deserializer.Deserialize(Of Dictionary(Of Integer, YAMLtempItem))(strtemp)
End Sub

我尝试过"大师级"房产的不同组合,但都无济于事。我也尝试过找到类似于JSONUtils的东西,它将从一些数据中生成一个类,但也没有成功。有人能为我指明获得这个嵌套列表的正确方向吗?

似乎masteries属性声明是错误的。您将键声明为整数列表,将值声明为整数,而文档将整数作为键,将列表作为值。所以不是

Public Property masteries As Dictionary(Of List(Of Integer), Integer)

你可能想要

Public Property masteries As Dictionary(Integer, Of List(Of Integer))

此外,YamlDotNet假定您的代码遵循标准的.NET命名约定,并且默认情况下假定YAML文档中存在camelBase。这意味着你的房产名称应该大写:

Class YAMLtempItem
Public Property BasePrice As Decimal?
Public Property Description As Dictionary(Of String, String)
Public Property GroupID As Integer
Public Property IconID As Integer?
Public Property MarketGroupID As Integer?
Public Property Mass As String
Public Property Name As Dictionary(Of String, String)
Public Property PortionSize As Integer
Public Property Published As Boolean
Public Property Volume As Decimal?
Public Property Radius As Double?
Public Property GraphicID As Integer?
Public Property SoundID As Integer?
Public Property RaceID As Integer?
Public Property SofFactionName As String
Public Property Capacity As String
Public Property FactionID As Integer?
Public Property Masteries As Dictionary(Of List(Of Integer), Integer)
End Class

最新更新