1

I have this json:

   [
      {
        "id": "89",
        "name": "Italy",
        "link": "https://int.soccerway.com/national/italy/a100/?ICID=SN_02_89",
        "iso": "IT"
      }
   ]

I'm trying to deserialize it with Newtonsoft.JSON, so I created a class model:

public class Country
{
    public string id { get; set; }
    public string name { get; set; }
    public string link { get; set; }
    public string iso { get; set; }
}

and the deserialization:

var json = JsonConvert.DeserializeObject<Country>(content);

content contains the json above, anyway, this will return:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'SWP.Models.Country' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.

utop
  • 111
  • 9

1 Answers1

4

Your JSON is an array so try this:

var json = JsonConvert.DeserializeObject<List<Country>>(content);
CodingYoshi
  • 25,467
  • 4
  • 62
  • 64