在LUA表中插入JSON的所有属性和值

在LUA表中插入JSON的所有属性和值,json,lua,Json,Lua,我想在LUA表中插入JSON的属性名和值 local function convert_table(tbl_test) local output_table = {} for i, v in pairs(tbl_test) do output_table [string.lower(i)] = string.lower(v) end return output_table end local test = cjson.d

我想在LUA表中插入JSON的属性名和值

local function convert_table(tbl_test)
 local output_table = {}
  for i, v in pairs(tbl_test) do
    output_table [string.lower(i)] = string.lower(v)                     
  end  
 return output_table
end
  local  test  =  cjson.decode(inputJson)
  local  final =  convert_table(test)
如果我的JSON是

 {    "test": "abc",
      "test1": "EDF",
      "test2": "PNG" }
但它不适用于以下JSON(JSON中的JSON)

虽然可以使用Luas模式机解析上述JSON示例中的嵌套结构,但这与预期目的相去甚远,而且一般来说,对于除专用库之外的任何东西来说都是复杂的

更可行的解决方案:
或者使用一个更强大的工具,如LPEG来构建您的解析器(这仍然需要一些时间),或者只使用任何可用的用于Lua的json解析器。

luarocks install cjson
您得到了什么结果?我也在使用cjson,它运行良好(商业工具)。你应该得到一个嵌套数组。
{
  "upper": {
    "test": "abc",
    "test1": "EDF",
    "test2": "PNG",
  }, 
  "lower": {
    "test3": "aabc",
    "test4": "edfa",
    "test5": "png"
  }
}