//get请求返回json对象:在这里插入代码片
public HttpResponseMessage Get()
{
List < User > userslist= new List<User>() {
new User() { uid = 1, name = "张三1" },
new User() { uid = 2, name = "张三2" },
new User() { uid = 3, name = "张三3" },
new User() { uid = 4, name = "张三4" },
new User() { uid = 5, name = "张三5" },
new User() { uid = 6, name = "张三6" } ,
new User() { uid = 7, name = "张三7" } ,
new User() { uid = 8, name = "张三8" }
};
HttpResponseMessage httpReponseMessage = new HttpResponseMessage();
string jsonstr = JsonConvert.SerializeObject(userslist);
httpReponseMessage.Content = new StringContent(jsonstr);
return httpReponseMessage;
}
实现效果:
[{"uid":1,"name":"张三1"},{"uid":2,"name":"张三2"},{"uid":3,"name":"张三3"},{"uid":4,"name":"张三4"},{"uid":5,"name":"张三5"},{"uid":6,"name":"张三6"},{"uid":7,"name":"张三7"},{"uid":8,"name":"张三8"}]