首页 > Web开发 > 详细

ASP.NET Core中将Json字符串转换为JsonResult

时间:2020-12-23 19:13:33      阅读:248      评论:0      收藏:0      [点我收藏+]

ASP.NET Core中返回JsonResult

最近在使用NET 5.0做WebApi中,发现只能返回string类型,不能用JsonResult返回实体,于是查阅资料找到解决办法。
两种方式分别为:

1.返回string类型

return new JsonResult(string)

2.JsonResult输出实体

    //此处需要引用Newtonsoft.Json,在NuGet中下载
    string jsonStr = JsonConvert.SerializeObject(classOutJson);
    return new ContentResult { Content = jsonStr, ContentType = "application/json" };

ASP.NET Core中将Json字符串转换为JsonResult

原文:https://www.cnblogs.com/Drock/p/14179505.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!