FastJson用法

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            var zoo1 = new zoo();

            zoo1.animals = new List<animal>();
            zoo1.animals.Add(new cat() { Name = "hello kitty", legs = 4 });
            zoo1.animals.Add(new dog() { Name = "dog1", tail = true });
            string json= fastJSON.JSON.Instance.ToJSON(zoo1); //序列化
            var z = fastJSON.JSON.Instance.ToObject<zoo>(json); //反序列化

            Console.WriteLine(z.animals[0].Name);
            Console.Read();
        }
    }

    public class animal { public string Name { get; set; } }
    public class cat : animal { public int legs { get; set; } }
    public class dog : animal { public bool tail { get; set; } }
    public class zoo { public List<animal> animals { get; set; } 
}

 

https://www.cnblogs.com/hjblog/archive/2012/11/19/2776869.html

 

如何屏蔽对象本身的一些属性

FastJSON.JSONParameters param = new FastJSON.JSONParameters();
param.EnableAnonymousTypes = true;
string reqJson = FastJSON.JSON.ToJSON(reqAllDaKaJiLu,param);

 

 

 

 

posted @ 2018-05-11 19:54  zhaogaojian  阅读(287)  评论(0编辑  收藏  举报