FANDOM


--Retrieves json data from a file  (needs to be between comments e.g: "--[[]]--"
 
local p ={}
function p.getJsonData(sJsonFile)
    sJsonFile = sJsonFile or "Module:Crow/json"
    local oJsonFile = require(sJsonFile) 
    if (oJsonFile) then
        sJsonFile,sResult = pcall(function () 
            return require("Module:JSON"):decode(oJsonFile)
        end)
    end
    return sResult or {}
end
 
return p
 
--local p ={}
--function p.getJsonData(sJsonFile)
--    sJsonFile = sJsonFile or "Module:Crow/json"
--    local oJsonFile = mw.title.new( sJsonFile):getContent()
--    local tJsonCrow 
--    if (oJsonFile) then
--        local sJsonFile,sResult = pcall(function () 
--            --remove comments from code then parse it
--            tJsonCrow=oJsonFile:sub(5,string.len(oJsonFile)-4) 
--            if (tJsonCrow) then
--                tJsonCrow = require("Module:JSON"):decode(tJsonCrow)
--            end
--        end)
--    end
--    return tJsonCrow 
--end
--
--return p