WebAPI学习笔记(2)返回值为Json格式

 1 [HttpPost]
 2 public HttpResponseMessage GetAll()
 3 {
 4             List<IssueModel> issueModelList = new List<IssueModel>();
 5 
 6             try
 7             {
 8                 IssueBLL issueBLL = new IssueBLL(AdminUserToken);
 9                 issueModelList = issueBLL.GetAllIssueModelList();
10             }
11             catch(Exception ex)
12             {
13 
14             }
15 
16             string content = ConvertJson.List2Json<IssueModel>(issueModelList);
17 
18             HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(content, Encoding.GetEncoding("UTF-8"), "application/json") };
19             return result;
20 }
1 public static string List2Json<T>(IList<T> list)
2 {
3       return Newtonsoft.Json.JsonConvert.SerializeObject(list);
4 }

【原文出处】http://www.51aras.com/?id=40

  

原文地址:https://www.cnblogs.com/61007257Steven/p/11717980.html