Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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.

  • You cannot reply to this topic
No replies to this topic

#1 FrontBack   Members   -  Reputation: 222

Like
0Likes
Like

Posted 31 May 2014 - 11:18 AM

Hi everybody! smile.png

 

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:

{
    "Header": {
        "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?

 

Thank you in advance! wink.png


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


Sponsor:



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.



PARTNERS