【发布时间】:2023-03-30 16:49:01
【问题描述】:
我正在尝试反序列化一个包含国家/地区列表的 json 对象,但我不断收到错误消息
类型 System.String' 不支持数组的反序列化。
我能够从 API 中检索 JSON 对象(国家列表),但是当我尝试反序列化 JSON 对象时
这是我获取国家列表并将它们绑定到国家列表模型的方法
public List<CountriesList> GetCountries()
{
try
{
string apiCountriesUrl = "https://restcountries.eu/rest/v2/all";
string response = GetServiceCallByUrl(apiCountriesUrl);
var countriesObj = System.Web.Helpers.Json.Decode<List<CountriesList>>(response);
return countriesObj;
}
catch (Exception exception)
{
throw exception;
}
}
我的国家列表模型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ApplicationPortal.Models
{
public class CountriesList
{
public string name { get; set; }
public string callingCodes { get; set; }
}
}
【问题讨论】:
-
我知道在帖子标题中正确添加两次单词并不能帮助它自行纠正。
标签: c# json asp.net-mvc rest deserialization