最近使用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" };
本文解决在使用Core3.1进行WebAPI开发时,如何正确地将实体类转换为JSON格式并设置正确的Content-Type为application/json的问题。
1885

被折叠的 条评论
为什么被折叠?



