Is there a way to reset $id in JSON response for each HTTP Request?

◇◆丶佛笑我妖孽 提交于 2020-01-24 00:26:08

问题


XYZController.cs

[HttpPost]
public async Task<ActionResult> Post([FromBody] T inputContext)
{
       var outputContext = Process(inputContext);
       return StatusCode(200, outputContext );
}

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
     services.AddMvc().AddJsonOptions(options =>
            {
                UpdateJsonSettings.ConfigureJsonFormatter(options.SerializerSettings);
            });
}

UpdateJsonSettings.cs

internal static void ConfigureJsonFormatter(JsonSerializerSettings settings)
{
       settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
       settings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
       settings.Converters.Add(new StringEnumConverter());
}

HttpResponse Try 1:

{ "$id": "1", "bill": { "$id": "2", "type": "TYPE1",

HttpResponse Try 2:

{ "$id": "28", <--- NOT SURE WHY ON THE SECOND REQUEST $ID starts with 28 :( --> "bill": { "$id": "29", "type": "TYPE1",

HttpResponse Try 3:

{ "$id": "55", <--- NOT SURE WHY ON THE SECOND REQUEST $ID starts with 55 :( --> "bill": { "$id": "56", "type": "TYPE1",

I am using Newtonsoft.Json (11.0.2)

来源:https://stackoverflow.com/questions/59832635/is-there-a-way-to-reset-id-in-json-response-for-each-http-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!