首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我仍然从我的控制器得到全面的json响应?

为什么我仍然从我的控制器得到全面的json响应?
EN

Stack Overflow用户
提问于 2021-07-08 14:03:50
回答 1查看 65关注 0票数 0

我有一个Asp.Net Core v5.0.7。客户端是一个ReactJs.Net应用程序。

我所有的控制器都有以下标记:

代码语言:javascript
复制
[Consumes("application/json")]
[Produces("application/json")]

我的Startup.cs文件ConfigureServices方法包含:

代码语言:javascript
复制
services.AddControllers()
                .AddNewtonsoftJson(options => { 
                    options.SerializerSettings.MaxDepth = 2;
                    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                });

但我还是要让我的儿子更有深度:

代码语言:javascript
复制
[
    {
        "itemNumber": "11BRC",
        "itemDescription": "Flat head Phillips Wood screw C-Pak 2x1/4",
        "featured": false,
        "categoryName": "Screws",
        "category": {
            "categoryId": 1003,
            "parentId": 3056,
            "name": "Screws",
            "parent": {
                "categoryId": 3056,
                "parentId": 0,
                "name": "Fasteners",
                "parent": null,
                "children": [
                    {
                        "categoryId": 3036,
                        "parentId": 3056,
                        "name": "Nuts",
                        "children": null,
                        "title": "Nuts",
                        "description": "Fastener Nuts",
                        "keywords": " Anchor, cage, classic, clinch, castle,nuts",
                        "pageContent": "<span style=\"font-style:italic; font-weight:bold; font-size:16pt;\"><span style=\"color:Blue; border-color:Blue; font-style:normal;\">NUTS</span><br/>Nuts and bolts are among the most expansive categories of hardware</span>. <br/>Options run the gamut, with coupling, locking, flanged, hex, square and more. We offer numerous material, finish and size options. When it comes to industrial nuts and bolts, <br/><span style=\"color:Navy; border-color:Navy; font-weight:bold;\">Fastener Superstore has a comprehensive selection for your manufacturing or assembly needs. We provide products in bulk so that your business is stocked with reliable, well made fasteners. When it comes to the hardware you use, it always pays to do business with the best.</span>",
                        "bannerGroupId": 0,
                        "inactive": 0,
                        "issitecategory": 0,
...

是否需要将[JsonIgnore]添加到导航属性中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-09 17:34:12

解决方案:我用AutoMapper将所有东西都压平为dto

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68303166

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档