这个EPGP World of Warcraft addon输出一个epgp.lua数据库文件。将Lua数据转换为JSON
我写了一个plugin将Lua数据转换成JSON对象以显示在公会网站上。它正在老版本的插件中工作,但现在我无法正确地转换文件。以下是两个显示转换问题的摘录 - 请参阅this demo。
第一作品在形成嵌套数组极大:
["roster_info"] = {
{
"Agantica", -- [1]
"ROGUE", -- [2]
"09/03-2013", -- [3]
}, -- [1]
{
"Intikamim", -- [1]
"PALADIN", -- [2]
"17/02-2013", -- [3]
}, -- [2]
},
变得
"roster_info" : [
[
"Agantica",
"ROGUE",
"09/03-2013"
],
[
"Intikamim",
"PALADIN",
"17/02-2013"
]
]
但串replacment认为这下一个片段作为嵌套阵列时,它应是一个内部的对象阵列:
["bonus_loot_log"] = {
{
["player"] = "Magebox",
["timestamp"] = "2013-03-07 13:44:00",
["coinsLeft"] = "-1",
["reward"] = "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r",
}, -- [1]
{
["player"] = "Lîutasila",
["coinsLeft"] = "-1",
["timestamp"] = "2013-03-07 13:47:00",
}, -- [2]
},
变得
"bonus_loot_log" : [
[
"player" : "Magebox",
"timestamp" : "2013-03-07 13:44:00",
"coinsLeft" : "-1",
"reward" : "|cffa335ee|Hitem:86815:0:0:0:0:0:0:632235520:90:0:445|h[Attenuating Bracers]|h|r"
],
[
"player": "Lîutasila",
"coinsLeft": "-1",
"timestamp": "2013-03-07 13:47:00"
]
]
以下是仅适用于第一个片段的字符串转换脚本。
lua_string
.replace(/\[(.*)\]\s\=\s/g,'$1:') // change equal to colon & remove outer brackets
.replace(/[\t\r\n]/g,'') // remove tabs & returns
.replace(/\}\,\s--\s\[\d+\]\}/g,']]') // replace sets ending with a comment with square brackets
.replace(/\,\s--\s\[\d+\]/g,',') // remove close subgroup and comment
.replace(/,(\}|\])/g,'$1') // remove trailing comma
.replace(/\}\,\{/g,'],[') // replace curly bracket set with square brackets
.replace(/\{\{/g,'[[') // change double curlies to square brackets
.replace(/EPGP_DB\s\=/,'');
所以,我需要一些帮助让Lua能够正确转换对象数组(第二个示例)。
[epgp.lua](https://github.com/Mottie/epgp/blob/master/epgp.lua)是如何生成的?如果它是生成此输出的lua代码,则可以编辑该代码并使用LuaJSON库/模块。 – hjpotter92 2013-04-27 18:59:58
当你退出魔兽世界时,它是由插件生成的。您所做的只是将原始数据文件上传到您的网站。 – Mottie 2013-04-27 19:00:58
这是因为你用'方括号替换集合结尾的评论'和'将双曲线改成方括号'行。双数组不是必须的数组。阵列中的对象也是Lua中的双曲。 – 2013-04-27 19:58:42