There is json . I try through Newtonsoftjson bring it to the class. Gives an error message. It seems to do everything as before. I do not understand what the error is

 var m = JsonConvert.DeserializeObject<Rootobject>(json).Property1.Select(x=>x.value).ToList(); public class Rootobject { public Class1[] Property1 { get; set; } } public class Class1 { public string value { get; set; } public string label { get; set; } public string firm { get; set; } } [ { "value": "CL", "label": "CL", "firm": "ACURA" }, { "value": "CSX", "label": "CSX", "firm": "ACURA" } ] 

Newtonsoft.Json.JsonSerializationException: "Cannot deserialize the current JSON array (eg [1,2,3]) into the 'Rootobject' type .

    1 answer 1

    You want to get a Rootobject object as a Rootobject . This JSON corresponding to the structure of this class is deserialized:

     { "Property1": [ { "value": "CL", "label": "CL", "firm": "ACURA" }, { "value": "CSX", "label": "CSX", "firm": "ACURA" } ]} 
    • Well, json comes from the server, I don’t have to choose - Rajab
    • 2
      JsonConvert.DeserializeObject<Class1[]> - Igor