Module:Json parameter test: Difference between revisions
Jump to navigation
Jump to search
No edit summary Tags: Manual revert Reverted |
No edit summary Tag: Manual revert |
||
| Line 4: | Line 4: | ||
-- JSON-Daten in einem Lua-String | -- JSON-Daten in einem Lua-String | ||
local jsonData = frame.args.jsonData | local jsonData = frame.args.jsonData | ||
-- Entferne Escape-Zeichen | -- Entferne Escape-Zeichen | ||
jsonData = jsonData:gsub("\\/", "/") | jsonData = jsonData:gsub("\\/", "/") | ||
-- | -- JSON-Daten in Lua-Tabelle umwandeln | ||
local json = mw.text.jsonDecode(jsonData) | |||
local result = {} | |||
for _, item in ipairs(json) do | |||
local title = item.data.title | |||
local classNames = item.data["class names"] | |||
table.insert(result, "== " .. title .. " ==") | |||
table.insert(result, "* " .. table.concat(classNames, "\n* ")) | |||
end | |||
return table.concat(result, "\n\n") | |||
end | end | ||
return p | return p | ||
Revision as of 09:21, 24 May 2024
Documentation for this module may be created at Module:Json parameter test/doc
local p = {}
function p.generateClassLists(frame)
-- JSON-Daten in einem Lua-String
local jsonData = frame.args.jsonData
-- Entferne Escape-Zeichen
jsonData = jsonData:gsub("\\/", "/")
-- JSON-Daten in Lua-Tabelle umwandeln
local json = mw.text.jsonDecode(jsonData)
local result = {}
for _, item in ipairs(json) do
local title = item.data.title
local classNames = item.data["class names"]
table.insert(result, "== " .. title .. " ==")
table.insert(result, "* " .. table.concat(classNames, "\n* "))
end
return table.concat(result, "\n\n")
end
return p