using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AccpStudentMIS
{
    //此类目的是防治序列化Json字符串时的循环引用问题
    //此类为Object类的扩展方法,需要引用Newtonsoft.Json.dll类
    //使用方法:在Controller中调用 Content(对象.ToJsonString(), "text/html;charset=UTF-8");方法来返回Json
    public static class ObjectExtentions
    {
        public static string ToJsonString(this Object obj)
        {

            JsonSerializerSettings jsSettings = new JsonSerializerSettings();
            jsSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            return JsonConvert.SerializeObject(obj, jsSettings);
        }
    }
}