YAML文件中的嵌套列表-在VB.net中创建类时遇到麻烦(夏娃在线SDE)

时间:2018-11-06 12:08:32

标签: vb.net yaml yamldotnet

我对YAML格式和VB.net总体上还是很陌生的(与VB6一起工作了大约5年并进行迁移,这个项目有点像是学习练习)。我也在使用yamldotnet软件包。

此刻,我正在修改一些发布的代码,以解析Eve Online SDE中的.yaml文件,因为SDE已将新字段添加到yaml文件中。理想情况下,我想在调用API来从SDE文件中获取静态信息时使用该文件。

我无法为“ masteries”字段的“ temporary”类添加属性。我已经编辑了en / de / fr / etc。说明以方便阅读。

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的东西,该东西将从一些数据生成一个类,但结果也很短。有人能指出正确的方向来获取此嵌套列表吗?

1 个答案:

答案 0 :(得分:0)

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

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

您可能想要

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

此外,YammlDotNet假定您的代码遵循标准的.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 Class