POSTed Json body requires surrounding quotes
I have a controller method declared like this:
[HttpPost]
public override IHttpActionResult Post([FromBody]string data)
{
// do stuff
}
When testing with Advanced Rest Client, or Powershell, I find that my Json body must be surrounded by single quotes. Example: instead of
{"name":"Elroy", "age":99}
I have to provide
'{"name":"Elroy", "age":99}'
If not in quotes, the my method receives an empty value for the "data" parm.
My ARC client DOES specify content-type="application/json"
That's not right, is it? The outer quotes shouldn't be necessary, right?
That's correct because JSON is transmitted as a string over the wire, not as an object graph. Hence the need for the quotes to denote that it is a string.
链接地址: http://www.djcxy.com/p/48618.html上一篇: cURL Windows中的双/单引号
下一篇: 张贴的Json正文需要周围的引号