Json response truncated in web api using asp.net core

I have a web api that returns a json object for me on my site. The problem is this:

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

, , 20 , - 2033, , . MaxJsonLength web.config, , , - .net, , .

+13
5

, json - , (ASP.NET Core 2.0) Newtonsoft.Json :

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

, , - JSON. , , , . , .

, json, JSonConvert.SerializeObject(), , .

+1

, , ., ,

@IngoB , ( @FailedUnitTest ) JSON , - , ReferenceLoopHandling Serialize , .

:

  1. NetTopologySuite.IO.GeoJSON
  2. - ConfigureServices():

    services.AddMvc(options =>
        {
            options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(Point)));
        })
        .AddJsonOptions(options =>
        {
            foreach (var converter in GeoJsonSerializer.Create(new GeometryFactory(new PrecisionModel(), 4326)).Converters)
            {
                options.SerializerSettings.Converters.Add(converter);
            }
        });
    
0

, , , SQL- , JSON JSON .

0

2033 , , SQL Server. , :

var queryWithForJson = "SELECT ... FOR JSON";
var conn = new SqlConnection("<connection string>");
var cmd = new SqlCommand(queryWithForJson, conn);
conn.Open();
var jsonResult = new StringBuilder();
var reader = cmd.ExecuteReader();
if (!reader.HasRows)
{
    jsonResult.Append("[]");
}
else
{
    while (reader.Read())
    {
        jsonResult.Append(reader.GetValue(0).ToString());
    }
}
0

Source: https://habr.com/ru/post/1683592/


All Articles