【发布时间】:2018-12-18 00:38:13
【问题描述】:
目前通过curl发布此数据:
{"test2":"hello","test3":"world"}
我的帖子是这样的:
curl --header "Content-Type: application/json" --request POST --data '{"test2":"hello","test3":"world"}' http://localhost/test
这是我请求的一部分:
ngx.req.read_body()
local data = ngx.req.get_body_data()
if not data then
ngx.say("err: ",err)
return
end
ngx.status = ngx.HTTP_OK
local eJson = cjson.encode(data)
local dJson = cjson.decode(eJson) -- decode json to lua table
ngx.say("Encoded: "..eJson);
ngx.say("Decoded: "..dJson);
编码和解码的 Json 输出:
Encoded: "{\"test2\":\"hello\",\"test3\":\"world\"}"
Decoded: {"test2":"hello","test3":"world"}
我相信它应该是这样的:
{"test" = "hello", "test2" = "world"}
我怎么会得到不同的输出?
【问题讨论】: