String truncate when performing append

3

The code below serializes a JSON list and gives an append variable the result . However, from a certain amount of records (350), the text contained in result has a modified part for "..." . I performed the tests by serializing the entire list directly and also through StringBuilder but obtaining the same result, only with the "..." in different places.

string result = string.Empty;
foreach(item in collection)
{
    string json = JsonConvert.Serialize(item);
    result += json; 
}

Excerpt from broken json:

  

{"cnae1": null, "cnae2": null, "cnae3": null ... A) "

How should it be:

  

{"cnae1": null, "cnae2": null, "cnae3": null, "part": null, "number": null, "type"

    
asked by anonymous 05.04.2016 / 15:00

1 answer

4

There's "nothing wrong" ...

I ran a test using the same code base as yours:

using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace TesteConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var lista = new List<Teste>();
            for (int i = 0; i < 300; i++)
                lista.Add(new Teste{id = i, nome = "Teste "+ i});

            var json = JsonConvert.SerializeObject(lista);

            Console.WriteLine(json);


            string result = string.Empty;
            foreach (var item in lista)
            {
                result += JsonConvert.SerializeObject(item);
            }


            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}


public class Teste
{
    public int id { get; set; }
    public string nome { get; set; }
}

Result of var json = JsonConvert.SerializeObject(lista) :

[{"id":0,"nome":"Teste 0"},{"id":1,"nome":"Teste 1"},{"id":2,"nome":"Teste 2"},{"id":3,"nome":"Teste 3"},{"id":4,"nome":"Teste 4"}
[...]
{"id":297,"nome":"Teste 297"},{"id":298,"nome":"Teste 298"},{"id":299,"nome":"Teste 299"}]

Result of string result :

{"id":0,"nome":"Teste 0"}{"id":1,"nome":"Teste 1"}{"id":2,"nome":"Teste 2"}{"id":3,"nome":"Teste 3"}{"id":4,"nome":"Teste 4"}
    [...]
    {"id":297,"nome":"Teste 297"}{"id":298,"nome":"Teste 298"}{"id":299,"nome":"Teste 299"}

I think the problem is only in the visualization and familiarization of the IDE ... If you in debug mode "hover" on top of the variable you want to see, you will see a reticence in case of what you are inspecting have a content larger than "fit" in the inspection preview:

05.04.2016 / 16:47