c# - 如何在 .net 核心控制器中返回 Json 对象?
问题描述
我目前正在使用一个使用 API 的简单网站。到目前为止,我只有原始的 json 数据,我想我会使用它,直到我可以访问来进行 api 调用。如何以最简单的方式返回我的 json 数据?
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace LiuOrg.Controllers
{
[ApiController]
[Route("[controller]")]
public class OrganisationController : ControllerBase
{
private string Summaries = @"{
'pointInTime': '2019-11-04T09:29:35.9425587Z',
'organisationViewType': 'Organisation',
'tree': {
'organisationId': 'efc0d74d-82323-2323',
'canonicalPath': 'LIU',
'shortName': 'LIU',
'enabled': true,
'fullName': {
'en': 'Linköping University',
'sv': 'Linköpings universitet'
},
'financialUnit': -1,
'organisationType': 'Company',
'children': [{
'organisationId': 'd1340837-2323-32323',
'canonicalPath': 'LIU/IBL',
'shortName': 'IBL',
'enabled': true,`enter code here`
....
[HttpGet]
public IActionResult Get()
{
return Json(new { Summaries });
}
} }
解决方案
推荐阅读
- sqlite - sqlite3 表无法链接到 Access
- python - Python在空格上拆分,除了单词之间和逗号之后
- eiffel - 在没有断言的情况下在运行时检查没有内容
- php - PHP - 达到 open_basedir 最大安全性
- python - ImportError:无法在 Python 3.6 虚拟环境中导入名称“is_scalar”
- c - 为什么 opendir() 会更改传递给它的文件路径字符串?
- java - 布尔值不继承
- google-apps-script - PageNavigationType 与表单不匹配
- javascript - 使用节点服务器爬虫选择 Web 窗口提示
- javascript - 无递归的自我复制按钮