标签:
//方法一:直接返回序列化后的json文件 public static HttpResponseMessage ConvertToJson(this Object obj) { String str=""; if (obj is String || obj is Char) { str = obj.ToString(); } else { string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj); } HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") }; return result; }
//方法二:global.asax.cs文件中加上 HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
标签:
原文地址:http://www.cnblogs.com/BABLOVE/p/4499751.html