相关疑难解决方法(0)

无法将JSON数组反序列化为类型--Json.NET

我试图将json数据反序列化为模型类,但我失败了.这是我做的:

    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();
        }
    }
Run Code Online (Sandbox Code Playgroud)

这就是我的模型的样子:

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 { …
Run Code Online (Sandbox Code Playgroud)

.net c# serialization json json.net

10
推荐指数
2
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

json ×1

json.net ×1

serialization ×1