Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web api 返回空JSON响应,而不是空响应{}_Asp.net Web Api_Httpresponsemessage - Fatal编程技术网

Asp.net web api 返回空JSON响应,而不是空响应{}

Asp.net web api 返回空JSON响应,而不是空响应{},asp.net-web-api,httpresponsemessage,Asp.net Web Api,Httpresponsemessage,我有一个WEB API,它有时返回空数据。 我期待下面的格式作为回应 {"cardResponse" : null} 但是我得到了{}作为回应。有什么想法吗 我的方法定义如下所示: public HttpResponseMessage Opeation(string input1, [FromUri] input2 request) return语句如下所示: return Request.CreateResponse(HttpStatusCode.OK, response); 响应类结构

我有一个WEB API,它有时返回空数据。 我期待下面的格式作为回应

{"cardResponse" : null}
但是我得到了
{}
作为回应。有什么想法吗

我的方法定义如下所示:

public HttpResponseMessage Opeation(string input1, [FromUri] input2 request)
return语句如下所示:

return Request.CreateResponse(HttpStatusCode.OK, response);
响应类结构:

public class RootResponse    {

    public CardResponse cardResponse{ get; set; }

}

  Public class CardResponse  {

    public string CardName { get ; set;}  
}

您在JSON格式化程序中将
NullValueHandling
选项设置为
NullValueHandling.Ignore
。检查WebApiConfig是否替换了默认的格式化程序,或者有人可以关闭默认的空值传递
JsonMediaTypeFormatter

它是哪种类型的
response
?这里不是ASP专家,但我很确定您需要发布更多的代码。在最后一个代码片段中,
response
的值是多少?显示关于该问题的代码line@OrelEraki编辑了这个问题。添加了响应ClassWow。非常感谢:)看来我加了那句话。