我有一个Web API接受(POST)JSON对象,该对象具有多个名称及其对应的值,然后将其添加到我的localDB。这是POST的代码。
public HttpResponseMessage PostAddItems(Item ItemValue)
{
try
{
if (ModelState.IsValid)
{
using (ItemsDBEntities ItemEntity = new ItemsDBEntities())
{
ItemEntity.Items.Add(ItemValue);
ItemEntity.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK + "Item has been Posted!");
}
}
else
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, "Model state is invalid");
}
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
}
}
我需要知道在添加()之前如何检查JSON名称。