我如何从C#返回JSON,但删除响应D:null
如何从我的服务响应中删除d:null? 我尝试了许多选项,它继续返回值d:null,我不知道该怎么做来解决问题,
我添加了我的c#代码,我的web.config的配置以及服务的响应,您可以看到正确的响应:200,但它继续添加值D:null
[WebMethod]
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public void test(string numberDoc)
{
if (!inicializo) inicializa();
string resp = "200";
WebException webException = null;
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
// Context.Response.ContentType = "application/json";
Response des = new Response();
des.response = resp;
Context.Response.Write(js.Serialize(des));
}
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="DebugJSonBehavior" >
<enableWebScript />
<!--need set automaticFormatSelectionEnabled attribute -->
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DebugJSonBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
这是我调用Postman服务的响应 { “响应”:“ 200” } { “ D”:空 }
谢谢
how can I remove d:null from my service response?
I have tried many options and it continues to return the value d:null and I don't know what else can be done to solve the problem
I add my c# code, the configuration of my web.config and the response of the service, where you can see the correct response response:200 but it continues adding the value d:null
[WebMethod]
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public void test(string numberDoc)
{
if (!inicializo) inicializa();
string resp = "200";
WebException webException = null;
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
// Context.Response.ContentType = "application/json";
Response des = new Response();
des.response = resp;
Context.Response.Write(js.Serialize(des));
}
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="DebugJSonBehavior" >
<enableWebScript />
<!--need set automaticFormatSelectionEnabled attribute -->
<webHttp automaticFormatSelectionEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DebugJSonBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
this is my response when i call the service from postman
{
"response": "200"
}{
"d": null
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我的解决方案
this was my solution
使用此代码,它将返回我在映像中看到的内容,其中d:null在响应末尾添加了postman
现在返回一个字符串邮递员在响应中包括d,而我不don' t知道如何删除D:
响应邮递员

With this code it returns me what you see in the image where d:null is added at the end of the response in postman
now returning a string postman keeps including the d in the response and I don't know how to remove d:
response postman

这对我有用。
this works for me.