反斜線造成Client端收到參數,反序列化JSON失敗

Designed by Freepik
API回傳JSON字串到Client端時(c#接收),
會因為多餘的反斜線造成Client端收到時,反序列化JSON失敗,
只要將API回傳參數改為HttpResponseMessage物件就可以
圖片來源Designed by Freepik


程式碼如下
  1. 回傳改為HttpResponseMessage物件
#region 取得設定
[Route("api/GetIDList/")]
[HttpGet]
public HttpResponseMessage GetIDList()
{
  HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
  httpResponseMessage.Content = new StringContent(sJsonString, System.Text.Encoding.UTF8, "application/json");
  return httpResponseMessage;
}
#endregion

沒有留言:

張貼留言

技術提供:Blogger.