Json Ignore

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace demo
{
    public class DynamicJsonContractResolver: DefaultContractResolver
    {
        private readonly string[] _props;

        public DynamicJsonContractResolver(params string[] prop)
        {
            this._props = prop;
        }

        protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            return base.CreateProperties(type, memberSerialization).Where(p => !this._props.Contains(p.PropertyName)).ToList();
        }
    }
}
posted @ 2021-08-23 15:59  天藐水瓶  阅读(44)  评论(0编辑  收藏  举报