【发布时间】:2016-07-05 21:51:57
【问题描述】:
我在 c# 客户端中使用 At WebApi 2.2 OData v4 服务。
在服务器端,我将异常包装到 Microsoft.Odata.Core.ODataError 对象中。
在 Microsoft OData V4 DataServiceClient 客户端中,我在以下代码块中捕获了异常。
try
{
//Post message to server
}
catch (DataServiceClientException ex)
{
string result = ex.Message;
ODataError error = JsonConvert.DeserializeObject(result) as ODataError;
}
这里我得到了 error 对象的空值。
但是result 对象具有以下Json 字符串值。
{
"error":{
"code":"Custom Error","message":"The INSERT statement conflicted with the FOREIGN KEY constraint...."
}
}
问题:
如何将Json 字符串转换为ODataError 对象?
我的要求是从上面的Json 字符串中读取消息属性,如var errmsg = error.message; 有没有其他选择?
【问题讨论】:
标签: c# asp.net-web-api odata odata-v4 dataservice