-1
我创建C#应用程序,它会从Web服务的响应,并将它作为DTO对象像Newtonsoft.Json.JsonSerializationException在反序列化JSON响应C#
List<Models.iLabDTO.RootObject> response = new List<Models.iLabDTO.RootObject>();
public async Task<IHttpActionResult> Get()
{
......
var request_returnDataObj = JsonConvert.DeserializeObject<Models.iLabDTO.RootObject>(responsefile);
response.Add(request_returnDataObj);
}
return Ok(response);
列表中,但它抛出错误,如
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Error converting value "on" to type 'System.Boolean'. Path
'il_response.c_forms[0].fields[0].required', line 1, position 354.
</ExceptionMessage>
<ExceptionType>Newtonsoft.Json.JsonSerializationException</ExceptionType>
如果我只是return OK(response)
没有使用response.Add(request_returnDataObj)
它工作正常。但我无法返回对象
看起来它的'il_response.c_forms [0] .fields [0] .required'的值有问题,因为它的值是“on”,比如“true”。如果你想用boolean标志打开和关闭,你需要有一个JsonConverter类的自定义实现。看到这里,https://stackoverflow.com/questions/14524669/how-to-get-newtonsoft-to-deserialize-yes-and-no-to-boolean – Bearcat9425
可能相关:https://stackoverflow.com/questions/ 6284936 /为什么是一个复选框发布一个值的 –
如果添加更多的信息,它会更容易帮助。似乎发送你的'变种响应=新列表();'回服务器包含包含值'on'而不是TRUE;或'FALSE'因此消息'”的属性打开“键入'System.Boolean''。 'RootObject'的属性和类型是什么?如果你看看回应并比较属性和值,你会发现更多。 –
surfmuggle