This class
class X{
public string a{get;set}
public string b{get;set}
}
is serialized like
{..., inst:{a:"value", b:"value"}, ...}
I need object of my class to be serialized like this:
{..., inst: x, ...}
Where x is a+b How can 开发者_运维百科I customize JSON serialization process from my class?
Checkout Newton-softs JSON serializer. Its pretty sweet.
Have you tried making a and b private, and then have something like
public string x { get { return a + b; } }
Try it like this
class X{
public string a{private get;set;}
public string b{private get;set;}
public string x {get{ return a + b; }}
}
Having a private get removes it from serialization but still allows it to be set. The other option is to do it like this.
class X{
public string a{set;}
public string b{set;}
public string x {get{ return a + b; }}
}
精彩评论