我有一个类,看起来像在C#:序列化对象的一部分,JSON
public class MyClass
{
public string Id { get; set; }
public string Description { get; set; }
public string Location { get; set; }
public List<MyObject> MyObjectLists { get; set; }
}
,我只是想序列化JSON 一部分该对象的:刚刚标识, 说明和位置属性,以便导致JSON看起来就像这样:
{
"Id": "theID",
"Description": "the description",
"Location": "the location"
}
是否有如何做到这一点?
但如何在序列化中使用该功能?我应该把它作为一个论据还是什么? –
你实际上不需要做任何事情。 Json.Net自动查找签名为'bool ShouldSerailizePropertyName'的方法,并在序列化时使用这些方法。我将为示例添加代码。 – GBreen12