我遇到了问题,当我在
然而,当我从参数中省略了“[”和“]”时,它不起作用:
curl
中省略JSON-RPC
请求参数的"[和]"部分时,无法使curl
和Json
(Node.js
)正常工作。我正在使用命名参数(即对象,而不是数组)。
以下内容可以正常工作:
curl -v -i POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method":"registerPerson", "params": ["{\"username\":\"morten10\",\"password\":\"mypass\"}"], "id":1 }' \
http://localhost:3000
然而,当我从参数中省略了“[”和“]”时,它不起作用:
curl -v -i POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method":"registerPerson", "params": {\"username\":\"morten10\",\"password\":\"mypass\"}, "id":1 }' \
http://localhost:3000
而 Jayson 给出了这个错误信息:
TypeError: First argument must be a string or Buffer
然而,根据JSON-RPC 2.0规范和其示例,当我使用命名参数时,应该能够从params中排除"[ and ]"部分,就像这个例子一样:
--> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}
<-- {"jsonrpc": "2.0", "result": 19, "id": 4}
我没有理解什么?
谢谢!
curl -v -i POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method":"registerPerson", "params": "{\"username\":\"morten10\",\"password\":\"mypass\"}", "id":1 }' http://localhost:3000
使Jayson在我的代码被执行之前给出以下消息:{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid request"}}
想象一下。 - ilsundal