Lua: 如何解析http post请求的结果?

我正在用Lua编写一个http客户端来访问rest web服务。

WebService的结果应该是这个json格式:

{
   "code": "123456789",
   "valid_until": "09/09/2020"
}

这是我的Lua脚本:

param_1 = arg[1];
param_2 = arg[2];

http = require("socket.http");
ltn12 = require("ltn12");
path = "http://www.url.com:8080/api/";
body = [[ {"number_id":"b8ce37fb-2061-4aea-975b-57a8e2d355ce","param_1":"]]..param_1..[[","param_2":"]]..param_2..[["} ]];
response_body = { }
res, code, response_haders, status = http.request {
    url = path,
    method = "POST",
    headers =
    {
        ["X-Access-Key"] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        ["Content-Type"] = "application/json",
        ["Content-Length"] = body:len()
    },
    source = ltn12.source.string(body),
}
print("res:"..res);
print("code:"..code);
print("status:"..status);

当我运行我的脚本时,这就是我得到的结果:

res:1
code:201
statusHTTP/1.0 201 CREATED

为什么我得到1作为结果,我该如何解析结果?

点赞