我有一个Asp.Net Core APIv5.0.7。客户端是ReactJs.Net应用程序。
我的所有控制器都标有:
[Consumes("application/json")]
[Produces("application/json")]
我的Startup.cs文件ConfigureServices
方法包含:
services.AddControllers()
.AddNewtonsoftJson(options => {
options.SerializerSettings.MaxDepth = 2;
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
但我仍在以完整的深度取回我的json:
[
{
"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]
添加到导航属性中?
解决方案:我用AutoMapper将所有东西都扁平化为dto-