Ошибка при обработке Json - Cannot deserialize the current JSON array because the type requires a JSON object - C# (232725)
Формулировка задачи:
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll Additional information: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Test.Form_Main+RootObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
public class RootObject { public string test { get; set; } public string test2 { get; set; } public string test3 { get; set; } } string json = "[{ "test":"12213","test2":"24242","test3":"34535"]"; RootObject newM = JsonConvert.DeserializeObject<RootObject>(json); rTB_Status.Text = newM.test;
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Test.Form_Main+RootObject' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1.
Решение задачи: «Ошибка при обработке Json - Cannot deserialize the current JSON array because the type requires a JSON object»
RootObject newM = JsonConvert.DeserializeObject<RootObject>(json); rTB_Result.Text = newM.test;
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д