【发布时间】:2016-06-12 11:09:22
【问题描述】:
我从 Android 应用发送 JSON 数据。在服务器端我有问题 - Web API 服务器 控制器没有获得参数。从客户端我发送这样的 json 数据:
{ "TypeID ": "1",
"FullName": "Alex",
"Title": "AlexTitle",
"RegionID": "1",
"CityID ": "1",
"Phone1": "+7(705)105-78-70"
}
感谢您的帮助,如果您有一些信息,请告诉我想法,谢谢! 这是控制器
[System.Web.Http.HttpPost]
public HttpResponseMessage PostRequisition([FromBody]string requisition)
{
Requisition postReq = new Requisition();
if (!String.IsNullOrEmpty(requisition))
{
dynamic arr = JValue.Parse(requisition);
//PostReq model = JsonConvert.DeserializeObject<PostReq>(requisition);
postReq.FullName = arr.FullName;
postReq.CityID = Convert.ToInt32(arr.CityID);
postReq.RegionID = Convert.ToInt32(arr.RegionID);
postReq.TypeID = Convert.ToInt32(arr.TypeID);
postReq.UserID = 8;
postReq.Title = arr.Title;
postReq.Date = Convert.ToDateTime(arr.Date, CultureInfo.CurrentCulture);
postReq.Decription = arr.Description;
postReq.Phone1 = arr.Phone1;
postReq.Activate = false;
postReq.ClickCount = 0;
try
{
db.Requisition.Add(postReq);
db.SaveChanges();
Message msg = new Message();
msg.Date = DateTime.Now;
msg.Type = "POST";
msg.Text = "OK";
db.Message.Add(msg);
db.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, postReq);
}
catch (Exception ex)
{
Message msg = new Message();
msg.Date = DateTime.Now;
msg.Type = "POST";
msg.Text = "ERROR";
db.Message.Add(msg);
db.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, ex.Message);
}
}
else
{
Message msg = new Message();
msg.Date = DateTime.Now;
msg.Type = "POST";
msg.Text = "null";
db.Message.Add(msg);
db.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, "null");
}
}
【问题讨论】:
-
这不是asp.net web api,它的C# web api 2.0
-
@Bhargav 抱歉,但在标签中我没有找到任何合适的标签
-
是的,我刚刚搜索了很奇怪,c# web api 2.0 被标记为 asp.net web api 很奇怪
标签: android json asp.net-web-api