我对YAML格式和VB.net非常陌生(在工作和迁移中,我与VB6一起工作了大约5年,这个项目有点像一个学习练习)。我也在使用yamldotnet包。
目前,我正在修改一些代码,这些代码是为了解析Eve Online SDE中的.yaml文件而发布的,因为SDE已经向yaml文件添加了新字段。理想情况下,我希望使用此文件,而不是调用API从SDE文件中获取静态信息。
我在为“masteries”字段的“temporary”类添加属性时遇到了问题。我已经编辑了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:\Users\ahooks\Dropbox\Eve VB.net Projects\EVE Resources\Static Data YAML\typeIDs.yaml")
TextBox3.Text = ""
Dim deserializer = New Deserializer()
Dim strtemp = New StringReader(input)
Dim itemTypes = deserializer.Deserialize(Of Dictionary(Of Integer, YAMLtempItem))(strtemp)
End Sub我尝试了'masteries‘属性的不同组合,但都没有效果。我也尝试过寻找类似于JSONUtils的东西,可以从一些数据中生成一个类,但也失败了。谁能给我指出获得这个嵌套列表的正确方向?
发布于 2018-11-07 00:46:04
masteries属性声明似乎是错误的。您将键声明为整数列表,将值声明为整数,而文档将整数作为键,列表作为值。因此,不是
Public Property masteries As Dictionary(Of List(Of Integer), Integer)你可能想要
Public Property masteries As Dictionary(Integer, Of List(Of Integer))此外,YamlDotNet假定您的代码遵循标准的.NET命名约定,并且在缺省情况下假定YAML文档中的camelCase。这意味着您的属性名称应该大写:
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 Classhttps://stackoverflow.com/questions/53171604
复制相似问题