在asp.net core中将JSON字符串转换为JsonResult

最近使用core3.1做webapi接口使用实体类输出参数发现要不就使用stirng返回,不能使用JsonResult 输出实体类

return new JsonResult(string)

但是发现出参不是 application/json 而是 text

以下是正确办法

string strJson = Newtonsoft.Json.JsonConvert.SerializeObject(classOutJson);
return new ContentResult { Content = strJson, ContentType = "application/json" };

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章