i have a JSON which can for example look like this:
{
"value":[
{
"Name":"Nik",
"Age":"17",
"Country":"Germany",
},
{
"Name":"Tom",
"Age":"20",
"Country":"Russia",
},
{
"Name":"Sila",
"Age":"12",
"Country":"Switzerland",
}
]
}
The Keys of the properties like "Name" and "Age" are dynamic and can vary. The JSON could also look like this:
{
"value":[
{
"Prename":"Nik",
"Age":"17",
"Country":"Germany"
"Car":"Merc"
},
{
"Prename":"Nik",
"Age":"20",
"Country":"Russia"
"Car":"BMW"
},
{
"Prename":"Nik",
"Age":"12",
"Country":"Switzerland",
"Car":"Audi"
}
]
}
The important thing is the strcuture, this is what i want to build manually with Newtonsoft.Json
.
This is my current attempt:
var jArray = new JArray();
jArray.Add("Name");
jArray.Add("Nikola");
jArray.Add("Age");
jArray.Add("17");
jArray.Add("Country");
jArray.Add("Germany");
JObject o = new JObject();
o["Value"] = jArray;
string json = o.ToString();
Result:
{
"Value": [
"Name",
"Nikola",
"Age",
"17",
"Country",
"Germany"
]
}
I tried to solve it with this example from the newtonsoft Website, but as you can see it's really poor explained.