Module:Json parameter test: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
-- local jsonData = frame:callParserFunction('#visualdataquery:[[unique title::+]]', { '?articleid', schema = 'Data classes', format = 'json-raw' }) | -- local jsonData = frame:callParserFunction('#visualdataquery:[[unique title::+]]', { '?articleid', schema = 'Data classes', format = 'json-raw' }) | ||
local jsonData = frame.args.jsonData | local jsonData = frame.args.jsonData | ||
-- Entferne Platzhalter und unstrip | |||
jsonData = mw.text.killMarkers(jsonData) | |||
jsonData = mw.text.unstrip(jsonData) | |||
-- Überprüfe, ob jsonData gültig ist | -- Überprüfe, ob jsonData gültig ist | ||
if not jsonData or jsonData == '' then | if not jsonData or jsonData == '' then | ||
Line 19: | Line 25: | ||
debugInfo = debugInfo .. "Trimmed JSON Data: " .. tostring(jsonData) .. "\n" | debugInfo = debugInfo .. "Trimmed JSON Data: " .. tostring(jsonData) .. "\n" | ||
-- Debug: Gib die bereinigten JSON-Daten aus | -- Debug: Gib die bereinigten JSON-Daten aus |
Revision as of 11:40, 30 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 von der Parserfunktion abrufen
-- local jsonData = frame:callParserFunction('#visualdataquery:[[unique title::+]]', { '?articleid', schema = 'Data classes', format = 'json-raw' })
local jsonData = frame.args.jsonData
-- Entferne Platzhalter und unstrip
jsonData = mw.text.killMarkers(jsonData)
jsonData = mw.text.unstrip(jsonData)
-- Überprüfe, ob jsonData gültig ist
if not jsonData or jsonData == '' then
return "Keine JSON-Daten empfangen."
end
-- Debug: Gib die empfangenen JSON-Daten aus
local debugInfo = "Received JSON Data: " .. tostring(jsonData) .. "\n"
-- Entferne führende und nachfolgende Leerzeichen
jsonData = mw.text.trim(jsonData)
-- Debug: Gib die getrimmten JSON-Daten aus
debugInfo = debugInfo .. "Trimmed JSON Data: " .. tostring(jsonData) .. "\n"
-- Debug: Gib die bereinigten JSON-Daten aus
debugInfo = debugInfo .. "Cleaned JSON Data: " .. jsonData .. "\n"
-- JSON-Daten in Lua-Tabelle umwandeln
local success, json = pcall(mw.text.jsonDecode, jsonData)
if not success then
return debugInfo .. "Fehler beim Dekodieren der JSON-Daten: " .. tostring(json)
end
debugInfo = debugInfo .. "Decoded JSON Data: " .. mw.dumpObject(json) .. "\n"
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 debugInfo .. table.concat(result, "\n\n")
end
return p