Lua 代码中打印 json 键的值时获取空值问题

以下是服务端返回的带有 "\x00" 末尾的 json 响应:

{
  "STATUS": [{
    "STATUS":"S",
    "When":1470180059,
    "Code":11,
    "Msg":"Summary",
    "Description":"nsgminer 0.9.2"
  }],"SUMMARY": [{
    "Elapsed":2061,
    "MHS av":0.00,
    "Found Blocks":0,
    "Getworks":76,
    "Accepted":0,
    "Rejected":0,
    "Hardware Errors":0,
    "Utility":0.00,
    "Discarded":209,
    "Stale":0,
    "Get Failures":3,
    "Local Work":293,
    "Remote Failures":0,
    "Network Blocks":14,
    "Total MH":0.0000,
    "Work Utility":0.00,
    "Difficulty Accepted":0.00000000,
    "Difficulty Rejected":0.00000000,
    "Difficulty Stale":0.00000000,
    "Best Share":0
  }],
  "id":1
}\x00

我想在 Lua 代码中使用这个 json :

local output = stdnse.output_table()
local json_string = tostring(result:sub(1, -2))
local pos, value = json.parse(json_string)
output["Description"] = value["STATUS"][0]["Description"]
return output

但是当我打印它的时候,我得到了空值

点赞
用户6669875
用户6669875

我用将 JSON 转化为字符串,再将字符串转化为 JSON 表格的方法解决了这个问题。

local pos, value = json.parse(tostring(json_string))
output["Description"] = value["STATUS"][1]["Description"]
2016-08-10 20:43:51