I am using Newtonsoft.Json
for JSon serialize and De-serialize. I am having issue with List of object element with indent. My problem is I want to display 10 element in one row then again 10 elements and rest will in 3rd row. How it can be possible with JToken?
Below is my expected output.
"parameters": [
{
"description": "EnableTestValues",
"defaults": [
0,1,1,2,3,4,5,6,9,7,
99,12,85,14,66,78
],
"size": [
1,16
]
},
{
"description": "CEC_Emer_Stop_Val",
"defaults": [
false
],
"size": [
1,1
]
},
{
"description": "CEC_Emer_Stop_Sw",
"defaults": [
252
],
"size": [
1,1
]
}
]
But I am getting
"parameters": [
{
"description": "EnableTestValues",
"defaults": [
0,
1,
1,
2,
3,
4,
5,
6,
9,
7,
99,
12,
85,
14,
66,
78
],
"size": [
1,
16
]
},
{
"description": "CEC_Emer_Stop_Val",
"defaults": [
false
],
"size": [
1,
1
]
},
{
"description": "CEC_Emer_Stop_Sw",
"defaults": [
252
],
"size": [
1,
1
]
}
]
Issue is with default and size property.
For serialize and de-serialize I am using dynamic object. Code is as below:
dynamic mdcsJson;
using (StreamReader r = new StreamReader(mdcsJsonFilePath))
{
string fileContent = System.IO.File.ReadAllText(mdcsJsonFilePath, Encoding.GetEncoding(1250));
mdcsJson = JsonConvert.DeserializeObject(fileContent);
}
// Updating some values here
string strJson = JsonConvert.SerializeObject(mdcsJson)