首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >YAML文件中的嵌套列表-在VB.net中创建类时出现问题(eve online SDE)

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

Stack Overflow用户
提问于 2018-11-06 20:08:32
回答 1查看 224关注 0票数 0

我对YAML格式和VB.net非常陌生(在工作和迁移中,我与VB6一起工作了大约5年,这个项目有点像一个学习练习)。我也在使用yamldotnet包。

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

我在为“masteries”字段的“temporary”类添加属性时遇到了问题。我已经编辑了en/de/fr/等描述以便于阅读。

代码语言:javascript
复制
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

和我拥有的类,到目前为止,我一直将属性添加为

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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的东西,可以从一些数据中生成一个类,但也失败了。谁能给我指出获得这个嵌套列表的正确方向?

EN

回答 1

Stack Overflow用户

发布于 2018-11-07 00:46:04

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

代码语言:javascript
复制
Public Property masteries As Dictionary(Of List(Of Integer), Integer)

你可能想要

代码语言:javascript
复制
Public Property masteries As Dictionary(Integer, Of List(Of Integer))

此外,YamlDotNet假定您的代码遵循标准的.NET命名约定,并且在缺省情况下假定YAML文档中的camelCase。这意味着您的属性名称应该大写:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53171604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档