/// <summary>
/// 返回成json格式
/// </summary>
/// <param name="obj">要返回的json字符串</param>
/// <returns></returns>
public static HttpResponseMessage toJson(Object obj)
{
String str;
if (obj is String || obj is Char)
{
str = obj.ToString();
}
else
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
str = serializer.Serialize(obj);
}
HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
return result;
}
C#返回Json字符串
最新推荐文章于 2024-08-23 10:35:13 发布