WebAPI如何返回json

public HttpResponseMessage PostUser(User user) 
{ 
    JavaScriptSerializer serializer = new JavaScriptSerializer(); 
    string str = serializer.Serialize(user); 
    HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") }; 
    return result; 
} 

 

posted @ 2017-11-30 09:21  桃花雪  阅读(561)  评论(0编辑  收藏  举报