Json响应使用asp.net核心在Web API中被截断 [英] Json response gets truncated in web api using asp.net core

查看:183
本文介绍了Json响应使用asp.net核心在Web API中被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a web api that returns a json object for me to use on my website. the problem is this:

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

[{"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核心方面,所以我有点迷茫,为什么它会被截断.

as you can see it gets truncated, it weights 20kb, string length is 2033, so I wanted to know if there is a way to increase the max size of the response somehow. I tried the MaxJsonLength inside the web.config but it is not working, might be because of the .net core aspect so I am kinda lost, why it is getting truncated.

推荐答案

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

I don't know why the json response gets truncated at some point, but in my case (ASP.NET Core 2.0) I had to tell Newtonsoft.Json to ignore reference loops like so:

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

这篇关于Json响应使用asp.net核心在Web API中被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆