I want to generate this nested json via c# objects
{
"contest": {
"name": "eatfast"
},
"contestants": {
"player": [
{
"id": 1,
"name": "KILL",
"stats": {
"time": 5
}
},
{
"id": 2,
"name": "BILL",
"stats": {
"time": 16
}
}
]
}
}
Heres what I have
private static string FormatJson(string json)
{
dynamic parsedJson = JsonConvert.DeserializeObject(json);
return JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
}
private void button2_Click(object sender, EventArgs e)
{
string json = "{\"contest\": { \"name\": \"eatfast\"},\"contestants\": {\"player\": [";
Contestants test = new Contestants
{
id = 3,
name = "JESUS"
//stats;
};
json = json + JsonConvert.SerializeObject(test, Formatting.Indented) + "]}}" ;
System.IO.File.WriteAllText("test.txt", FormatJson(json));
}
Output
{
"contest": {
"name": "eatfast"
},
"contestants": {
"player": [
{
"id": 3,
"name": "JESUS"
}
]
}
}
Could you give me any ideas on how to add a player in this example, or how to add stats time, appreciate any help
Or should I do it manually using string manipulation?