Carlos28
Carlos28

Reputation: 2411

Json deserializing object as Dictionary

I'm serializing object let's call it X to Json, one of fields in X is type of object (here i assign different classes instances).

public object value
{
    get;
    set;
 }

So after deserialization I get value as Dictionary<propertyName, value>

["x", "valX"]
["y", "valY"]

I understand why this works that way, so my question is what is the best way to create propper class instance according to this value I can create new instane and assign propertieces:

new A() 
{
    x = value["x"],
    y = value["y"],
    .
    .
    .
}

But is there any beter way to achieve that?

Upvotes: 0

Views: 62

Answers (1)

Jens Cappelle
Jens Cappelle

Reputation: 111

I think this might help you: https://stackoverflow.com/a/3744505/6756334

It is solved with json.net (http://www.newtonsoft.com/json) an awesome lib for serializing and deserializing json in c#

Upvotes: 2

Related Questions