vb.带有数字的.NET对象初始化器



所以我有以下对象初始化器。这是一个API,我也试图发送数据。

Dim request = New With {
.data = New With {
.workspace = workspace,
.name = "Complex task test",
.notes = "These are task notes",
.projects = {"1202219487026592"},
.custom_fields = New With {
.21234515112 = "222"
}
}
}

问题是custom_fields需要gid, gid是数字。显然,我们不能使用数字,所以它会产生问题。

有别的办法吗?另一种声明它并获得相同结果的方法?

使用Dictionary(Of UInt64, String)将工作,假设您希望将custom_fields属性值序列化为JSON对象:

Dim request = New With {
.data = New With {
.workspace = workspace,
.name = "Complex task test",
.notes = "These are task notes",
.projects = {"1202219487026592"},
.custom_fields = New Dictionary(Of UInt64, String) From {
{ 21234515112, "222" }
}
}
}
Dim serializedJson = JsonConvert.SerializeObject(request)

小提琴:https://dotnetfiddle.net/NHrNqC

最新更新