【发布时间】:2013-11-15 15:58:58
【问题描述】:
您好,我将 xml 作为字符串传递
<AbcDto xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Abc">
<Id>2</Id>
<Description>sample string 4</Description>
<Name>sample string 3</Name>
<PolicyId>c17f5b9f-c9bf-4a3a-b09b-f44ec84b0d00</PolicyId>
<Status>Active</Status>
<TimeZoneId>USCentral</TimeZoneId>
</AbcDto>
当我尝试为 Web Api 创建自定义模型绑定器时
public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
{
var json = actionContext.Request.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrEmpty(json))
{
var jsonObject = (JObject) Newtonsoft.Json.JsonConvert.DeserializeObject(json);
var jsonPropertyNames = jsonObject.Properties().Select(p => p.Name).ToList();
作为参数传递给下面方法的json字符串是一个xml字符串 我在 Newtonsoft.Json.JsonConvert.DeserializeObject(json); 面临异常; 异常详情: 解析值时遇到意外字符:
【问题讨论】:
标签: json asp.net-mvc-4 c#-3.0 json.net json-deserialization