• Create Account

## Deserializing a class by JSON property with Json.Net

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1FrontBack  Members

Posted 31 May 2014 - 11:18 AM

Hi everybody!

My 2D side-scroller engine is based on assets, so every "class" is an asset. For example: every tile is an asset, every weapon is an asset, every bullet is an asset, so we have for example the "weapon01" asset, the "tile01" asset, and so on.

Everything (JSON, Lua script and textures) packed in a .zip file.

I was thinking about defining an asset with a JSON file, parsed with Json.Net:

{
"Type":"",
"Name":"",
"Author":"",
"Version":""
},
"Content": {
<variable content here>
}
}

The problem is that I was thinking about reading the type field in the header section, and according to its value deserializing the content section to the required class, but also carrying with me the header section, so for example: if the type (which is an enum) is FileType.Tile, I'll deserialize the content section as a tile, but carrying with it the header section, so when I call the deserialized tile object I can see its header, so its name, author and version.

How can I do that using Json.Net? Or should I change the way I make packages?

Edited by FrontBack, 31 May 2014 - 11:27 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.