在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" };

 

posted @ 2020-05-25 19:09  米晔  阅读(698)  评论(0)    收藏  举报