Is there a way to generate Serialized string of List <object> without any [ ]
we are doing serialization using following code
JsonConvert.SerializeObject(data)
[
{
"SessionId": "6d1ea52b-9f0c-4c32-835d-49e6db22efee",
"ComponentName": "WebRole",
"Message": "X"
},
{
"SessionId": "6d1ea52b-9f0c-4c32-835d-49e6db22efee",
"ComponentName": "WebRole",
"Message": "Y"
},
{
"SessionId": "6d1ea52b-9f0c-4c32-835d-49e6db22efee",
"ComponentName": "WebRole",
"Message": "Z"
},
{
"SessionId": "6d1ea52b-9f0c-4c32-835d-49e6db22efee",
"ComponentName": "WebRole",
"Message": "XY"
},
{
"SessionId": "6d1ea52b-9f0c-4c32-835d-49e6db22efee",
"ComponentName": "WebRole",
"Message": "XYZ",
"Payload": "X>>1"
}
]
Is there a way to remove above [ and ] , I have workaround to call Trim('[') and Trim(']') on serialize string. Is there any setting that come out of box from NewtonSoft which removes [ and ], also I dont want to make use of anonymous object.
[]then your resultant JSON would be invalid. You can copy and paste your output json check here json2csharp.comSubstringlike =>var newStr = jsonStr.Substring(1, jsonStr.Length - 1);newtonsoftto remove square brackets from json then It replies you that I am being programmed to produce only valid JSON, so how can I give you invalid JSON? So my suggestion is to go with string manipulation by usingTrimorSubstring