.NET 中 Json 反序列化的问题

Problems with Json deserialisation within .NET

我构建了以下 classes 我想存储数据的地方(帮助也可以在 c# 中)

Public Class DatasourceInfos
    Public Property DSContainer() As List(Of DatasourceInfo)
End Class

Public Class DatasourceInfo
    Public Property name As String
    Public Property description As String
    Public Property created As String
    Public Property modified As String
    Public Property identifier As String
    Public Property href As String
    Public Property cacheAvailable As Boolean
    Public Property id As ULong
End Class

我收到 json 格式的数据如下:

[{  "name":"MyName1",
    "description":"MyDescription1",
    "created":1244193265000,
    "modified":1264515442000,
    "identifier":"Identifier==",
    "href":"https://....",
    "cacheAvailable":true,
    "id":29},

    {"name":"MyName2",
    "description":"MyDescription2",
    "created":1244193265000,
    "modified":1264515442000,
    "identifier":"Identifier==",
    "href":"https://....",
    "cacheAvailable":true,
    "id":30}]

使用 RestSharp(解决方案不得使用 RestSharp)我尝试将数据放入我的 class 中:

Public Function getDatasources(ByVal _token As String) As String
    Dim client = New RestClient(_baseURI)
    Dim request = New RestRequest("/data", Method.GET)
    request.AddHeader("Authorization", "Basic " + _token)
    Dim response = client.Execute(Of DatasourceInfos)(request)
    Return response
End Function

但是查看 response object 没有任何映射到我的 classes。谁能告诉我我做错了什么?我将此代码与 SO 上的许多其他代码进行了比较,但我就是看不出有什么问题。

在显示的 json 中,没有任何与您的 DatasourceInfos 容器 class 相关的内容。为此,json 看起来像:

{
    "DSInfoItems":
     ...all your json ....
}

JSON.NET,至少,在尝试反序列化为 DatasourceInfos 时对格式大喊大叫,但很容易反序列化为 DatasourceInfo 的数组或列表:

Dim DS = JsonConvert.DeserializeObject(Of List(Of DataSource))(jstr)