It looks like a (not very good) attempt to represent XML in JSON. JSON looks like this:
[ { "page": 1, … }, [ { "id": "AFG", "name": "Afghanistan", … }, { "id": "BDI", "name": "Burundi", … }, … ] ]
While reasonable JSON (which, by the way, will map well with your model) will look like this:
{ "page": 1, …, "countries": [ { "id": "AFG", "name": "Afghanistan", … }, { "id": "BDI", "name": "Burundi", … }, … ] }
If you are sure that you want to use JSON (and not XML), you can do this by first deserializing JSON into the JSON.NET object model and then deserializing it in your model:
var json = client.DownloadString("http://api.worldbank.org/incomeLevels/LIC/countries?format=json"); var array = (JArray)JsonConvert.DeserializeObject(json); var serializer = new JsonSerializer(); var countryModel = serializer.Deserialize<CountryModel>(array[0].CreateReader()); countryModel.Countries = serializer.Deserialize<List<Country>>(array[1].CreateReader()); return countryModel;
Remember to change the Id properties to string , because that is what they are.
svick Feb 26 2018-12-12T00: 00Z
source share