0

I have to serialize some C# class data into JSON. For this purpose I use a MemoryStream and a DataContractJsonSerializer.

MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Person));
ser.WriteObject(stream1, p);
using (FileStream file = new FileStream("Write.json", FileMode.Create, FileAccess.ReadWrite))
{
    stream1.Position = 0;
    stream1.Read(stream1.ToArray(), 0, (int)stream1.Length);
    file.Write(stream1.ToArray(), 0, stream1.ToArray().Length);
    stream1.Close();
    file.Close();
}

Running the application like this produces this output:

{"age":42,"arr":[{},{},{}],"name":"John","value":null,"w":{}}

However, for my task I have to produce a JSON file where each entry is entered in a new line. Example:

"SomeData":[
{
    "SomeData" : "Value",
    "SomeData" : 0,
    "SomeData": [
        {
            "SomeData" : "Value",
            "SomeData" : 0
            ]
        }
    ]
}, etc. etc.

Any ideas as to how I can do this? Thanks in advance!

Vincent F
  • 371
  • 3
  • 17
Teodor Savov
  • 71
  • 1
  • 7
  • possible duplicate of [Tool to Unminify / Decompress JavaScript](http://stackoverflow.com/questions/822119/tool-to-unminify-decompress-javascript) – Peter Jun 02 '15 at 20:21
  • http://stackoverflow.com/questions/9834007/how-to-pretty-print-with-system-json – n0rd Jun 02 '15 at 20:44

1 Answers1

0

Ok, so if you want to do that just add this code answered in this question.

question here

Community
  • 1
  • 1
Bogdan Banciu
  • 169
  • 1
  • 6