RestSharp が特定の JSON 結果を逆シリアル化できるように、POCO クラスを構築しようとしています。問題は、ルート オブジェクトに nb_results キーと他のキーの辞書 ("0:"、"1:" など、それぞれが複雑な値を持つ) の両方が含まれていることです。
Dictionary(Of Integer, mediaGalleryData) と Dictionary(Of String, mediaGalleryData) の両方を試しました。どちらも機能しません。nb_results は常にシリアライズしますが、ディクショナリは決してシリアライズしません。
{
"nb_results": 2,
"0": {
"id": 51976254,
"title": "Bumblebee species Bombus terrestris",
"media_type_id": 1,
"creator_name": "paulrommer",
"creator_id": 201446851,
"thumbnail_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/51\/97\/62\/110_F_51976254_dVCbgGVey5xEuLkvk1e4vhnmPqxI4J0X.jpg",
"thumbnail_html_tag": "<img src=\"http:\/\/t1.ftcdn.net\/jpg\/00\/51\/97\/62\/110_F_51976254_dVCbgGVey5xEuLkvk1e4vhnmPqxI4J0X.jpg\" alt=\"Bumblebee species Bombus terrestris\" title=\"Photo: Bumblebee species Bombus terrestris\" width=\"110\" height=\"73\" \/>",
"thumbnail_width": 110,
"thumbnail_height": 73,
"affiliation_link": "http:\/\/api.fotolia.com\/id\/51976254",
"thumbnail_30_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/51\/97\/62\/30_F_51976254_dVCbgGVey5xEuLkvk1e4vhnmPqxI4J0X.jpg",
"thumbnail_30_width": 30,
"thumbnail_30_height": 20,
"thumbnail_110_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/51\/97\/62\/110_F_51976254_dVCbgGVey5xEuLkvk1e4vhnmPqxI4J0X.jpg",
"thumbnail_110_width": 110,
"thumbnail_110_height": 73,
"thumbnail_400_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/51\/97\/62\/400_F_51976254_dVCbgGVey5xEuLkvk1e4vhnmPqxI4J0X.jpg",
"thumbnail_400_width": 400,
"thumbnail_400_height": 267,
"licenses": [
{
"name": "XS",
"price": 1
},
{
"name": "S",
"price": 3
},
{
"name": "M",
"price": 5
},
{
"name": "L",
"price": 7
},
{
"name": "XL",
"price": 8
},
{
"name": "XXL",
"price": 10
},
{
"name": "X",
"price": 100
}
]
},
"1": {
"id": 44488015,
"title": "Vintage Style Birds, Bees and Banners Vector Set",
"media_type_id": 3,
"creator_name": "artnerdluxe",
"creator_id": 203491263,
"thumbnail_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/44\/48\/80\/110_F_44488015_hvEpYPw8yILDsnAi6BChYWXtzmiH6jWd.jpg",
"thumbnail_html_tag": "<img src=\"http:\/\/t1.ftcdn.net\/jpg\/00\/44\/48\/80\/110_F_44488015_hvEpYPw8yILDsnAi6BChYWXtzmiH6jWd.jpg\" alt=\"Vintage Style Birds, Bees and Banners Vector Set\" title=\"Vector: Vintage Style Birds, Bees and Banners Vector Set\" width=\"105\" height=\"110\" \/>",
"thumbnail_width": 105,
"thumbnail_height": 110,
"affiliation_link": "http:\/\/api.fotolia.com\/id\/44488015",
"thumbnail_30_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/44\/48\/80\/30_F_44488015_hvEpYPw8yILDsnAi6BChYWXtzmiH6jWd.jpg",
"thumbnail_30_width": 29,
"thumbnail_30_height": 30,
"thumbnail_110_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/44\/48\/80\/110_F_44488015_hvEpYPw8yILDsnAi6BChYWXtzmiH6jWd.jpg",
"thumbnail_110_width": 105,
"thumbnail_110_height": 110,
"thumbnail_400_url": "http:\/\/t1.ftcdn.net\/jpg\/00\/44\/48\/80\/400_F_44488015_hvEpYPw8yILDsnAi6BChYWXtzmiH6jWd.jpg",
"thumbnail_400_width": 380,
"thumbnail_400_height": 400,
"licenses": [
{
"name": "XS",
"price": 1
},
{
"name": "S",
"price": 3
},
{
"name": "M",
"price": 5
},
{
"name": "L",
"price": 7
},
{
"name": "XL",
"price": 8
},
{
"name": "XXL",
"price": 10
},
{
"name": "V",
"price": 5
},
{
"name": "XV",
"price": 40
}
]
}
}
これが私がこれまでに持っているクラスです:
Public Class mediaGallery
Public Property nb_results As Integer
Public Property results As Dictionary(Of String, mediaGalleryData)
End Class
Public Class mediaGalleryData
Public Property id As Integer
Public Property title As String
Public Property creator_name As String
Public Property creator_id As Integer
Public Property media_type_id As Integer
Public Property thumbnail_url As String
Public Property thumbnail_width As Integer
Public Property thumbnail_height As Integer
Public Property thumbnail_html_tag As String
Public Property thumbnail_30_url As String
Public Property thumbnail_30_width As Integer
Public Property thumbnail_30_height As Integer
Public Property thumbnail_110_url As String
Public Property thumbnail_110_width As Integer
Public Property thumbnail_110_height As Integer
Public Property thumbnail_400_url As String
Public Property thumbnail_400_width As Integer
Public Property thumbnail_400_height As Integer
Public Property licenses As List(Of licensedata)
End Class
Public Class licensedata
Public Property name As String
Public Property price As Integer
End Class
私のRestSharpを消費するコード:
Public Function getUserGalleryMedias(page As Integer?, nb_per_page As Integer?, thumbnail_size As Integer?, id As String, detail_level As Integer?) As mediaGallery
Dim request = New RestRequest("user/getUserGalleryMedias", Method.GET)
If page.HasValue Then request.AddParameter("page", page.Value)
If nb_per_page.HasValue Then request.AddParameter("nb_per_page", nb_per_page.Value)
If thumbnail_size.HasValue Then request.AddParameter("thumbnail_size", thumbnail_size.Value)
If Not String.IsNullOrEmpty(id) Then request.AddParameter("id", id)
If detail_level.HasValue Then request.AddParameter("detail_level", detail_level.Value)
Return Execute(Of mediaGallery)(request)
End Function