You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

26 lines
721 B

using System;
using System.Net.Http;
using System.Text;
using System.Web.Script.Serialization;
namespace EasyBL.WebApi.Common
{
public class HttpResponseExtension
{
public static HttpResponseMessage ToJson(Object obj)
{
String str;
if (obj is String || obj is Char)
{
str = obj.ToString();
}
else
{
var serializer = new JavaScriptSerializer();
str = serializer.Serialize(obj);
}
var result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
return result;
}
}
}