我使用c#和Newtonsoft.Json库对json进行序列化和反序列化。
我有一个这样的课程
public class Animal
{
[JsonProperty(PropertyName = "Dog")]
public Key value {get;set;}
}如果我将它实例化为
Animal a = new Animal{ Key = "bobby" };我序列化它,我会有一个像这样的json
{
"dog": "bobby"
}我可以动态更改序列化的PropertyName吗?例如,如果我想把"Bird“或"Cat”而不是"Dog“放进去怎么办?
发布于 2014-12-06 08:47:42
public class Animal
{
public KeyValuePair<string,string> value {get;set;}
}
Animal a = new Animal { value = new KeyValuePair("dog","boddy")};如果你想要鸟的话
Animal a = new Animal { value = new KeyValuePair("bird","bird1")};https://stackoverflow.com/questions/27326960
复制相似问题