Bir json verilerini bir model sınıfına serpiştirmeye çalışıyorum ancak başarısız oldum. İşte benim yaptığım:JSON dizisini türüne dönüştüremiyor - Json.NET
public CountryModel GetCountries() {
using (WebClient client = new WebClient()) {
var result = client.DownloadString("http://api.worldbank.org/incomeLevels/LIC/countries?format=json");
var output = JsonConvert.DeserializeObject<List<CountryModel>>(result);
return output.First();
}
}
Bu gibi benim modeli görünür: http://api.worldbank.org/incomeLevels/LIC/countries?format=json
En fazla bu hata şudur: Burada alıyorum Json görebilirsiniz
public class CountryModel
{
public int Page { get; set; }
public int Pages { get; set; }
public int Per_Page { get; set; }
public int Total { get; set; }
public List<Country> Countries { get; set; }
}
public class Country
{
public int Id { get; set; }
public string Iso2Code { get; set; }
public string Name { get; set; }
public Region Region { get; set; }
}
public class Region
{
public int Id { get; set; }
public string Value { get; set; }
}
:
JSON dizisini 'Mvc4AsyncSample.Models.CountryModel' türüne dönüştürülemez. Hat 1, pozisyon 1.
. Belki de XML formatını kullanırsanız daha iyi olur. – svick
Evet, öyle düşünüyorum. Dizinin içine tek bir nesne koydular. Sanırım orada olmamalıydı. Gezmek için herhangi bir yol var mı? – tugberk
XML çok daha temiz, bunun için giderdim: http://api.worldbank.org/incomeLevels/LIC/countries?format=xml –