I'm trying to save the player's inventory as a JSON data but I'm having a problem. I have a class Sword
which extends an abstract class Weapon
which extends another abstract class called Item
. This is what JSON file looks like with the Sword and Armor objects in it:
[
{
"category": {
"type": "Weapon",
"subtype": "Sword"
},
"id": 0,
"value": 1,
"name": "Wooden Sword",
"description": "Sword made out of wood",
"slug": "wooden_sword",
"stats": {
"wear": 100,
"damage": 5
}
},
{
"category": {
"type": "Armor",
"subtype": "Helmet"
},
"id": 1337,
"value": 1,
"name": "Steel Helmet",
"description": "Whatever...",
"slug": "steel_helmet",
"stats": {
"wear": 100,
"defence": 5,
"vitality": 3,
"dexterity": -1
}
}
]
How can I parse these objects into their respective C# objects, putting the first entry into a Sword
object and the second one into a Helmet
object. There will be other types of objects in there too, so it's not limited on these two.