@TechNOIR

C#. Как правильно разобрать JSON?

Добрый день!
Пытаюсь разобрать Json ответ от API на классы итд.
Классы сгенерировал на jsonutils.com

Скопировал в проект, прописал:
var fb = new WebClient() {Encoding = System.Text.Encoding.UTF8}.DownloadString(URI);
var list = JsonConvert.DeserializeObject<List<Example>>(fb);


Получаю следующее:
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[chat.Example]' 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.


Подскажите пожалуйста как решить проблему? Спасибо заранее!
JSON - ignn.ru/t/messages.json
  • Вопрос задан
  • 2197 просмотров
Пригласить эксперта
Ответы на вопрос 2
byte916
@byte916
У вас же в ошибке написано - вы пытаетесь объект превратить в массив. Классы у вас сгенерированы неправильно, ищите ошибку в них
Ответ написан
Комментировать
VoidVolker
@VoidVolker Куратор тега C#
Dark side eye. А у нас печеньки! А у вас?
Для генерации классов из JSON есть отличнейший сервис: https://app.quicktype.io/#r=json2csharp
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы