이 EPGP World of Warcraft addon은 epgp.lua 데이터베이스 파일을 출력합니다.Lua 데이터를 JSON으로 변환
나는 길드 웹 사이트에 표시하기 위해 Lua 데이터를 JSON 객체로 변환하기 위해 plugin을 썼다. 그것은 addon의 이전 버전에서 작동하지만 지금은 파일을 제대로 변환하려고하는 데 문제가 있습니다. 다음은 전환 문제를 보여주는 두 가지 코드입니다 (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"
]
]
된다 그러나이 내부 오브젝트해야 할 때 문자열 교체 기기가 중첩 된 배열로이 다음 조각을보고 : 중첩 된 어레이를 형성에 큰
첫 번째 작품 어레이 :
["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]
},
가
,536,913된다"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)는 어떻게 생성 되나요? 이 출력을 생성하는 루아 코드 인 경우 해당 코드를 편집하고 LuaJSON 라이브러리/모듈을 사용할 수 있습니다. – hjpotter92
월드 오브 워크래프트에서 로그 아웃하면 애드온에 의해 생성됩니다. 당신이 할 일은 원시 데이터 파일을 사이트에 업로드하는 것뿐입니다. – Mottie
이것은'대괄호로 끝나는 설정 바꾸기 '와'대괄호를 대괄호로 바꾸기'행 때문에 발생합니다. 이중 curlies는 배열 안의 배열을 의미 할 필요는 없습니다. 배열 내부의 Object는 Lua의 이중 curlies입니다. –