如何将一个以字符串形式表示的 JSON 数组转换为 Lua 表或解析它为 JSON

我找不到任何相关的东西,我有一个在数据库中的字段,它是库存数据,我有这个数组的字符串形式:

[{type:'item_standard',name:'hdlred',label:'Xenon Vermelho',weight:1,rare:0,can_remove:1,price:93,count:3},
{type:'item_standard',name:'hdlred',label:'Xenon Vermelho',weight:1,rare:0,can_remove:1,price:93,count:3},]

我想知道如何将其转换,然后我可以遍历每个索引(Lua),对于这个新手问题,真的很抱歉,但我真的在为这个问题自嘲...

点赞
用户2858170
用户2858170

以下是使用dkjson的示例:

local json = require("dkjson")
local dataTable, pos, err = json.decode(yourstring)

if not dataTable then print(err) end

但你可能需要在json字符串的键周围添加一些引号。

2021-01-13 22:36:29