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

☆樱花仙子☆ 提交于 2019-12-01 21:53:59
 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 }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!