最近在使用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" };

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-02-07
  • 2021-12-06
  • 2021-12-23
  • 2021-11-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-12-27
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案