4
使用反射,我能夠根據它們是繼承,聲明,公共,私人等過濾成員。有什麼辦法可以做同樣的排序使用JSon.NET序列化對象時過濾?序列化爲JSON(使用Json.Net),同時忽略繼承成員
我的代碼是目前:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public void addRequestParameters<T>(string key, T SerializableRequestParameters)
{
//Serialize the object
string json = JsonConvert.SerializeObject(SerializableRequestParameters, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
//Add it to an existing request (unrelated to this question)
((JObject)JSONRequest).Add(key, JToken.Parse(json));
}