Geni Lou

Geni Lou

  • NA
  • 101
  • 24.5k

JSON Response to List of Model

Oct 18 2021 11:31 PM

I have a model to get the list of countries
public class Coutry{
        public string country;
        public string region;
    }

I try to do this code but I encounter error:
    
var client = new RestClient("<API LINK HERE>");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
var content = response.Content; // raw content as string
dynamic json = JsonConvert.DeserializeObject(content);

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


the response of api:
{
    "status": "OK",
    "status-code": 200,
    "version": "1",
    "total": 57,
    "limit": 3,
    "offset": 0,
    "access": "public",
    "data": {
        "DZ": {
            "country": "Algeria",
            "region": "Africa"
        },
        "AO": {
            "country": "Angola",
            "region": "Africa"
        },
        "BJ": {
            "country": "Benin",
            "region": "Africa"
        }
    }
}


Answers (2)