无法从 C# 中的 IMGUR API 反序列化当前 JSON 对象错误
Cannot deserialize the current JSON object error from IMGUR API in C#
我正在尝试从 imgur 相册中获取所有图像。它适用于所有相册,除非我尝试从中获取图像
this album
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Imgur.API.Models.Impl.Image]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
这是我的代码,它抛出了异常。
public async Task<List<IImage>> dosomething()
{
IEnumerable<IImage> image = await Task.Run(AccessTheWebAsync);
return image.ToList(); ;
}
async Task<IEnumerable<IImage>> AccessTheWebAsync()
{
var client = new ImgurClient(token);
var endpoint = new AlbumEndpoint(client);
IEnumerable<IImage> images = await endpoint.GetAlbumImagesAsync(albumlink);
return images;
}
您传递的 albumlink
值不正确,它的末尾不应有 #0
。
albumlink
的值应该只是 Dc2k6
。
我不确定为什么 #0
在那里,我假设它可以 select 特定图像或其他东西,但我无法让它工作。为了证明它无关紧要,请在 #
:
之后添加任何其他值
我正在尝试从 imgur 相册中获取所有图像。它适用于所有相册,除非我尝试从中获取图像 this album
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Imgur.API.Models.Impl.Image]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
这是我的代码,它抛出了异常。
public async Task<List<IImage>> dosomething()
{
IEnumerable<IImage> image = await Task.Run(AccessTheWebAsync);
return image.ToList(); ;
}
async Task<IEnumerable<IImage>> AccessTheWebAsync()
{
var client = new ImgurClient(token);
var endpoint = new AlbumEndpoint(client);
IEnumerable<IImage> images = await endpoint.GetAlbumImagesAsync(albumlink);
return images;
}
您传递的 albumlink
值不正确,它的末尾不应有 #0
。
albumlink
的值应该只是 Dc2k6
。
我不确定为什么 #0
在那里,我假设它可以 select 特定图像或其他东西,但我无法让它工作。为了证明它无关紧要,请在 #
: