У меня есть эти два метода:
public async Task<List<PullRequest>> GetPullRequests(string name, string repoName)
{
var response = await GetHttpClient().GetAsync($"{Host}/repos/{name}/{repoName}/pulls");
return JsonConvert.DeserializeObject<List<PullRequest>>(await response.Content.ReadAsStringAsync());
}
public async Task<List<Repository>> GetRepositories(string name)
{
var response = await GetHttpClient().GetAsync($"{Host}/orgs/{name}/repos");
return JsonConvert.DeserializeObject<List<Repository>>(await response.Content.ReadAsStringAsync());
}
Но меня отпускает эта ошибка, когда я пробую выполнять это:
Cannot deserialize the current JSON object (e.g. { {ямс": "оцените" }) into type 'System. Collections. Generic. List '1 [Evaluator. Model. Repository]' because the type requires в JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this ошибка either change the JSON to в JSON array (e.g. [1,2,3]) or change the deserialized type so that it is в нормальный.NET type (e.g. not в primitive type like integer, not в collection type like an array or List) that хан be deserialized from в JSON object. JsonObjectAttribute хан also be added to the type to я вынудил it to deserialize from JSON object. Path 'messagВ, line 1, position 11.
Как я могу решать это?
Сообщение показывает, что это не array или заносит в список то, что ты хочешь deserializar, но объект простой, может быть, не будь должен использовать List<Repository>
а только Repository
, верни json, который ты получаешь в string, и это проанализируй
Используй
var response = await GetHttpClient().GetAsync($"{Host}/orgs/{name}/repos");
string result = await response.Content.ReadAsStringAsync();
принеси этот string к tool, как это
, чтобы получать структуру классов, что действительно mapea с json, что ты получаешь