public HttpResponseMessage collect(dynamic d) { Object data; string userId = string.Empty; if (d != null) { userId = d.userId; } if (string.IsNullOrEmpty(userId)) { data = new { success = false, backMsg = "请先登录再操作!" }; } else { try { BLL.handleCulture culture = new BLL.handleCulture(); bool flag = culture.collect(d); if (flag) { data = new { success = true }; } else { data = new { success = false, backMsg = "操作失败,请重试!" }; } } catch (Exception ex) { data = new { success = false, backMsg = "服务异常" }; } } JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(data); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") }); }