Normally when I use API's and get a Json string back I simply make a class to suit the string and populate that class using newton JsonConvert.DeserializeObject.
However I now have a Json string which 1 of the fields does not have a name.
{
"attacks": {
"114862720": {
"code": "115dc2b990153c41c33d519b26cc302a",
"timestamp_started": 1596782220,
"timestamp_ended": 1596782226,
"attacker_id": 580816,
"attacker_name": "chedders",
"attacker_faction": 32585,
"attacker_factionname": "Heart of a Pirate",
"defender_id": 65306,
"defender_name": "-Clansdancer",
"defender_faction": 0,
"defender_factionname": null,
"result": "Attacked",
"stealthed": 0,
"respect_gain": 4.14,
"chain": 3,
"modifiers": {
"fairFight": 3,
"war": 1,
"retaliation": 1,
"groupAttack": 1,
"overseas": 1,
"chainBonus": 1
}
},
"114862829": {
"code": "8bf08c8ceb9b72f05f40235310cd822e",
"timestamp_started": 1596782339,
"timestamp_ended": 1596782344,
"attacker_id": 580816,
"attacker_name": "chedders",
"attacker_faction": 32585,
"attacker_factionname": "Heart of a Pirate",
"defender_id": 964979,
"defender_name": "brko21",
"defender_faction": 0,
"defender_factionname": null,
"result": "Attacked",
"stealthed": 0,
"respect_gain": 4.11,
"chain": 4,
"modifiers": {
"fairFight": 3,
"war": 1,
"retaliation": 1,
"groupAttack": 1,
"overseas": 1,
"chainBonus": 1
}
}
}
}
After attacks is an ID which is unique to each entry.so building a class for this as I normally would just wont work as the ID is unknown.
Any pointers on how to deserialise this string would be most welcome.
public IDictionary<string, MyModel> Attacks { get; set; }Dictionary<string, MyType>. WhereMyTypeis a type that you define with all of the properties within each object, in the JSON document."attacks"to have the same fields?