基本上我使用.Net VB将JSON String格式传递给Response Body的Swagger-UI。 但响应主体显示的字符如" \" 我想摆脱它。
我的Json字符串在VB中看起来像这样
sJSON = "{""csid"":""" + customer.CSID.ToString() + """}"
目前的结果是:
{\" CSID \":\" 1234 \"}
期望的结果是:
{" CSID":" 1234"}
新编辑:
该字符串是从我的自定义打印JSON类生成的 它是我从HomeControllers模仿的Controller类附带的默认方法 我猜它需要设置" application / JSON"内容类型?
Public Function GetValue(ByVal id As Integer) As String
Return PrintJSON()
End Function
Function PrintJSON()
Dim sJSON As String
' Begin JSON object
sJSON = "{"
' Timestamp
sJSON = sJSON + """date"":""" + DateTime.Today().ToShortDateString + ""","
sJSON = sJSON + """time"":""" + DateTime.Today().ToShortTimeString + ""","
' Return list of parameters in a JSON object
sJSON = sJSON + ""
sJSON = sJSON + """record"":["
For Each customer In Customers
sJSON = sJSON + "{"
sJSON = sJSON + """csid"":""" + customer.CSID.ToString() + """"
sJSON = sJSON + "}"
If customer.Equals(Customers.Last) Then
sJSON = sJSON + "]"
Else
sJSON = sJSON + ","
End If
Next
sJSON = sJSON + "}"
Return sJSON
End Function
答案 0 :(得分:0)
好的,我找到了解决方案。 GetValue方法只能返回一个数据传输对象类。
Swagger将自动以JSON格式显示该类。
我确信希望在Swagger教程中解释得更清楚。