模块:JSON:修订间差异

来自乐园数据管理室
ヒカリ​(留言 | 贡献)
无编辑摘要
ヒカリ​(留言 | 贡献)
无编辑摘要
 
(未显示同一用户的2个中间版本)
第3行: 第3行:
function p.loadJson(pagename)
function p.loadJson(pagename)
   local title = mw.title.new(pagename, "JSON")
   local title = mw.title.new(pagename, "JSON")
   if not title.exists then error(title .. "不存在") end
  local content = title:getContent()
   return mw.text.jsonDecode(title:getContent())
   if not content then error(tostring(title) .. " 页面不存在") end
   return mw.text.jsonDecode(content)
end
end


return p
return p

2019年9月28日 (六) 23:47的最新版本

此模块的文档可以在模块:JSON/doc创建

local p = {}

function p.loadJson(pagename)
  local title = mw.title.new(pagename, "JSON")
  local content = title:getContent()
  if not content then error(tostring(title) .. " 页面不存在") end
  return mw.text.jsonDecode(content)
end

return p