【问题标题】:Extract Dictionary Object from another Object从另一个对象中提取字典对象
【发布时间】:2022-01-22 22:20:27
【问题描述】:

我配置了一个数据模型

Public Partial Class card
    <JsonProperty("faction")>
    Public Property Faction As Exile
    <JsonProperty("id")>
    Public Property Id As String
    <JsonProperty("image")>
    Public Property Image As String
    <JsonProperty("import_id")>
    Public Property ImportId As String
    <JsonProperty("kredits")>
    Public Property Kredits As Long
    <JsonProperty("rarity")>
    Public Property Rarity As Rarity
    <JsonProperty("set")>
    Public Property [Set] As [Set]
    <JsonProperty("text")>
    Public Property Text As Dictionary(Of String, String)
    <JsonProperty("title")>
    Public Property Title As Dictionary(Of String, String)
    <JsonProperty("type")>
    Public Property Type As TypeEnum
    <JsonProperty("can_create", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property CanCreate As String()
    <JsonProperty("exile", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property Exile As Exile?
    <JsonProperty("attack", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property Attack As Long?
    <JsonProperty("defense", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property Defense As Long?
    <JsonProperty("operationCost", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property OperationCost As Long?
    <JsonProperty("attributes", NullValueHandling:=NullValueHandling.Ignore)>
    Public Property Attributes As Attribute()
End Class

我希望提取 Title 字典中的所有值,所以基本上我将完整的键值对列在与对象本身不同的字典列表中。

我想我可以通过整个对象 For Each 并将它们添加到一个新的字典列表中,但是必须有一个更清洁/更快的方法来执行此操作?

【问题讨论】:

    标签: vb.net dictionary


    【解决方案1】:

    使用接受另一个字典的 Dictionary 构造函数

    Dim myCard As card
    ' deserialize to mycard
    Dim myTitle As New Dictionary(Of String, String)(myCard.Title)
    

    【讨论】:

      猜你喜欢
      • 2015-12-24
      • 2018-09-22
      • 1970-01-01
      • 2016-03-04
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      相关资源
      最近更新 更多