windows中josn格式错误。"was expecting double-quote to start field name"

发布时间 2023-04-17 13:17:17作者: funflux

错误示范:

$ curl -X POST localhost:8080/employees -H 'Content-type:application/json' -d '{"name": "Samwise Gamgee", "role": "gardener"}'</p>

报错如下:

"JSON parse error: Unexpected character ('n' (code 110)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('n' (code 110)): was expecting double-quote to start field name\n at

错误1:curl在windows中是另外一个命令的别名,不是linux中的那个curl。windwos中想要使用原版,需要安装curl,配置环境变量,并改成curl.exe 命令。

错误2:wind powershell 中JOSN单双引号问题。这里需要转义字符。

正确示例:

$ curl.exe -X POST localhost:8080/employees -H 'Content-type:application/json' -d '{\"name\": \"Samwise Gamgee\", \"role\": \"gardener\"}'