【发布时间】:2014-12-03 21:11:04
【问题描述】:
基本上,我正在打一场艰苦的战斗,以一种调用方想要的方式格式化我返回的数据。
我发现我可以“完美”地“响应。写入”数据,但 WebMethod 坚持要返回一些东西……即使它是空的。
<System.Web.Services.WebMethod> _
Public Shared Function api_method(ByVal key1 As String) As String
Dim test As Object = getReturnData(key1)
Dim json As String = New JavaScriptSerializer().Serialize(test)
json = Replace(json, """amount"":""", """amount"":")
json = Replace(json, """,""currency", ",""currency")
HttpContext.Current.Response.BufferOutput = True
HttpContext.Current.Response.ContentType = "application/json"
HttpContext.Current.Response.Write(json)
HttpContext.Current.Response.Flush()
End Function
有什么方法可以抑制这个 null 吗?
【问题讨论】:
-
尝试在刷新后添加一个 HttpContext.Current.Response.CompleteRequest()。
-
@Gridly - 我无法让 CompleteRequest 没有编译错误。我尝试了您所拥有的以及 HttpApplication.CompleteRequest()... 但是... HttpContext.Current.Response.End() 似乎已经解决了我的问题!!!
-
@Gridly - 不确定我的评论去了哪里,我告诉过你“谢谢,我已经修改了我的代码。”但是...... .CompleteRequest 在末尾添加了“null”......所以我必须使用.End。 (如果没有你的帮助,我仍然不会发现,再次感谢!!!)