我有一个如下所述的课程:
public class Employee {
[JsonProperty("emp_id")]
public int Id {get; set;}
[JsonProperty("emp_fname")]
public string Name {get;set;}
[JsonProperty("emp_lname")]
public string LastName {get;set;}
}
在上面的课程中,我分配了Newtonsoft Attribute进行序列化。
我有一个Employee
类的对象,现在我想通过JsonProperty
查找该属性并获取该属性的值。
例如,我想获取JsonProprty属性名称设置为emp_lname
的属性的值>
是否有一种方法可以通过反射来寻找价值?
我有一个如下所述的类:public class Employee {[JsonProperty(“ emp_id”)] public int Id {get; set;} [JsonProperty(“ emp_fname”)]公共字符串名称{get; set;} [...
您可以为此目的使用Json.NET自己的contract resolver。这样做将正确处理添加和不添加[JsonProperty(string name)]
属性的属性,以及直接应用naming strategies的对象。