我有一个Web API,它返回一个json对象供我在网站上使用。问题是这样的:

[
{
    "installment": 1,
    "date": "03\/01\/2016",
    "amount": "27.28",
    "status": "\"01BI000657\""
},
{
    "installment": 2,
    "date": "04\/01\/2016",
    "amount": "49.25",
    "status": "\"01BI000699\""
},
{
    "installment": 3,
    "date": "05\/01\/2016",
    "amount": "56.31",
    "status": "\"01BI000745\""
},
{
    "installment": 4,
    "date": "06\/01\/2016",
    "amount": "53.43",
    "status": "\"01BI000811\""
},
{
    "installment": 5,
    "date": "07\/01\/2016",
    "amount": "60.52",
    "status": "\"01EI279932\""
},
{
    "installment": 6,
    "date": "08\/01\/2016",
    "amount": "57.95",
    "status": "\"01BI000934\""
},
{
    "installment": 7,
    "date": "09\/01\/2016",
    "amount": "60.24",
    "status": "\"01BI001015\""
},
{
    "installment": 8,
    "date": "10\/01\/2016",
    "amount": "67.36",
    "status": "\"01EI298127\""
},
{
    "installment": 9,
    "date": "11\/01\/2016",
    "amount": "65.30",
    "status": "\"01BI001185\""
},
{
    "installment": 10,
    "date": "12\/01\/2016",
    "amount": "72.44",
    "status": "\"01BI001277\""
},
{
    "installment": 11,
    "date": "01\/01\/2017",
    "amount": "70.75",
    "status": "\"01BI001380\""
},
{
    "installment": 12,
    "date": "02\/01\/2017",
    "amount": "73.55",
    "status": "\"01BI001486\""
},
{
    "installment": 13,
    "date": "03\/01\/2017",
    "amount": "89.28",
    "status": "\"01BI001567\""
},
{
    "installment": 14,
    "date": "04\/01\/2017",
    "amount": "80.00",
    "status": "\"01BI001691\""
},
{
    "installment": 15,
    "date": "05\/01\/2017",
    "amount": "87.23",
    "status": "\"01BI001822\""
},
{
    "installment": 16,
    "date": "06\/01\/2017",
    "amount": "86.63",
    "status": "\"01BI002011\""
},
{
    "installment": 17,
    "date": "07\/01\/2017",
    "amount": "93.89",
    "status": "\"01BI002172\""
},
{
    "installment": 18,
    "date": "08\/01\/2017",
    "amount": "93.78",
    "status": "\"01BI002369\""
},
{
    "installment": 19,
    "date": "09\/01\/2017",
    "amount": "97.49",
    "status": "\"\""
},
{
    "installment": 20,
    "date": "10\/01\/2017",
    "amount": "104.81",
    "status": "\"\""
},
{
    "installment": 21,
    "date": "11\/01\/2017",
    "amount": "105.50",
    "status": "\"\""
},
{
    "installment": 22,
    "date": "12\/01\/2017",
    "amount": "112.87",
    "status": "\"\""
},
{
    "installment": 23,
    "date": "01\/01\/2018",
    "amount": "114.15",
    "status": "\"\""
},
{
    "installment": 24,
    "date": "02\/01\/2018",
    "amount": "118.67",
    "status": "\"\""
},
{
    "installment": 25,
    "date": "03\/01\/2018",
    "amount": "131.57",
    "status": "\"\""
},
{"ins


如您所见,它被截断了,它的权重为20kb,字符串长度为2033,所以我想知道是否有办法以某种方式增加响应的最大大小。我在web.config中尝试了MaxJsonLength,但是它不起作用,可能是因为.net核心方面,所以我有点迷茫,为什么它会被截断。

最佳答案

我不知道为什么json响应有时会被截断,但是在我的情况下(ASP.NET Core 2.0)我不得不告诉Newtonsoft.Json忽略这样的引用循环:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddJsonOptions(
            options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
        );
}

10-08 09:13