下载app免费领取会员
class Program
{
static void Main(string[] args)
{
var m = new JsonModel()
{
Id = 0,
Name = "nnnn"
};
var json = JsonConvert.SerializeObject(m, new JsonSerializerSettings()
{
ContractResolver = new MyContractResolver(new List<string>(){ "Id" })
});
Console.WriteLine(json);
}
}
public class JsonModel
{
[JsonProperty("myId")]
public int Id { get; set; }
public string Name { get; set; }
}
public class MyContractResolver : DefaultContractResolver
{
private List<string> _names = null;
public MyContractResolver(List<string> names)
{
_names = names;
}
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
string name = member.Name;
if (_names.Contains(name))
return base.CreateProperty(member, memberSerialization);
return null;
}
}
本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。
上一篇:关于revit中幕墙的绘制