i m working on a .net project. I need to convert a json model (which has dynamicly changed numerical node name) to csharp class. Second node's name is changing dynamically, thats why i can not write a jsonproperty like this : [JsonProperty("353503")]. I did not see a json model like this. I tried many thing but couldn't achive. What should i do?
{
"standings": {
"353493": {
"id": "353493",
"name": "root name",
"n": "0",
"ut": "2021-08-23T20:54:12+00:00",
"standing_participants": {
"4273616": {
"id": "4273616",
"n": "14",
"ut": "2021-08-23T20:54:11+00:00",
"rank": "1",
"standing_data": [
{
"id": "146906199",
"standing_type_paramFK": "1",
"value": "6",
"code": "points",
"n": "2",
"ut": "2021-08-23T20:54:11+00:00",
"sub_param": ""
},
{
"id": "146906200",
"standing_type_paramFK": "2",
"value": "8",
"code": "goalsfor",
"n": "2",
"ut": "2021-08-23T20:54:11+00:00",
"sub_param": ""
}
]
},
"4273617": {
"id": "4273617",
"n": "14",
"ut": "2021-08-23T20:54:11+00:00",
"rank": "2",
"standing_data": [
{
"id": "146906198",
"standing_type_paramFK": "1",
"value": "6",
"code": "points",
"n": "2",
"ut": "2021-08-23T20:54:11+00:00",
"sub_param": ""
},
{
"id": "146906201",
"standing_type_paramFK": "2",
"value": "8",
"code": "goalsfor",
"n": "2",
"ut": "2021-08-23T20:54:11+00:00",
"sub_param": ""
}
]
}
}
}
}
}
When i try this, it works
public partial class SampleStandingModel
{
[JsonProperty("standings")]
public Standings Standings { get; set; }
}
public partial class Standings
{
[JsonProperty("353493")]
public Standing Standing { get; set; }
}
But when i remove [JsonProperty("353493")] line, it doesn't work
public partial class SampleStandingModel
{
[JsonProperty("standings")]
public Standings Standings { get; set; }
}
public partial class Standings
{
public Standing Standing { get; set; }
//or this:
// public Dictionary<int, Standing> Standing { get; set; }
}
my json parse code like below:
var deserializedObject = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
The important point on my problem, second node (standing-> 353493) name is numerical and dynamic.
My question as marked answered before, but there is no same problem. Older problems are about dynamic types or objects. This problem about numerical and dynamic node name. I didn't find a solution for two days.