【发布时间】:2015-03-12 15:18:39
【问题描述】:
http://localhost:15641/api/Complaints/NewComplaint
用户代理:提琴手
内容类型:application/json
主机:本地主机:15641
内容长度:63
请求正文 { "CostCentre":"test","ComplaintText":"这是测试投诉" }
WebApi 控制器
[Route("api/Complaints/NewComplaint")]
[HttpPost]
public void CreateNewComplaint(BLL.Complaint complaint)
{
//call BLL Create complaint method
}
}
我的对象是空值 我在哪里做错了? 我在控制器上设置断点投诉对象设置为所有空值 如果我不传递值投诉对象,则它自身为空 我怎样才能传递对象
【问题讨论】:
-
属性名称的引号在 JSON 中是强制。我还会考虑删除不必要的回车。所以你的请求正文应该是
{"CostCentre": "test", "ComplaintText":"djfiojdsifneiorfj wefnuiwnfjkwe fuwe uiehfuiwf jibui"},并且(如果提琴手没有自动这样做)调整你的请求的Content-Length。 -
您可能还想将您的路线名称从 NewCompalint 调整为正确拼写的 NewComplaint。
-
您好,我在 JSON 中为属性名称添加引号,但对象仍然填充了空值
-
所以更新您的问题以准确显示您在做什么,以免这种遗漏不会分散其他想要帮助您的人的注意力。
标签: c# json asp.net-web-api fiddler