Здравствуйте, учусь использовать Refit и у меня проблема.
это модели
public partial class Source
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
public partial class Article
{
[JsonProperty("source")]
public Source Source { get; set; }
[JsonProperty("author")]
public string Author { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
[JsonProperty("urlToImage")]
public Uri UrlToImage { get; set; }
[JsonProperty("publishedAt")]
public DateTimeOffset PublishedAt { get; set; }
[JsonProperty("content")]
public string Content { get; set; }
}
Это интерфейс с запросом и его параметры.
public interface IRest
{
[Get("/v2/top-headlines")]
Task<List<Article>> GetArticles(string country, string apiKey"RemovingKey");
}
Это запрос в ArticleViewModel
private async Task GetTaskAsync()
{
var WeApp = RestService.For<IRest>("https://newsapi.org/");
var result = await WeApp.GetArticles("co");
}
Когда я отлаживаю, чтобы увидеть данные, это выходит
Newtonsoft.Json.JsonSerializationException
Message=Cannot deserialize the current JSON object (e.g. {"name":"value"})
into type 'System.Collections.Generic.List`1[RefitNpt.Models.Article]'
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<T>)
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.
Path 'status', line 1, position 10.
Я искал решения, но решить их не смог, учусь самостоятельно.