基本上我正在进行一场艰苦的战斗,以一种主叫方想要的方式格式化我返回的数据。
我发现我可以" response.write"数据"完美"但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?
答案 0 :(得分:1)
将其设为Sub而不是函数:
<System.Web.Services.WebMethod> _
Public Shared Sub api_method(ByVal key1 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 Sub