首页 > 解决方案 > 如何在 .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 });
        }
  }  }

标签: c#.net-core

解决方案


推荐阅读