Editing
Module:Json parameter test
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} function p.generateClassLists(frame) -- JSON-Daten in einem Lua-String von den übergebenen Argumenten abrufen -- local jsonData = frame.args.jsonData -- Benannter Parameter "json" -- 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:preprocess('{{#visualdataquery:[[unique title::+]]|?articleid|schema = Data classes|format = json-raw}}') -- local jsonData = '[{"pagetitle":"Classes/Gender","data":{"unique title":"Classes/Gender","title":"Gender","class names":["female","male","diverse"]}},{"pagetitle":"Classes/Age","data":{"unique title":"Classes/Age","title":"Age","class names":["0 - 14","15 - 29","30 - 44","45 - 59","60 +"]}},{"pagetitle":"Classes/Districts","data":{"unique title":"Classes/Districts","title":"Districts","class names":["District 1","District 2","District 3","District 4"]}},{"pagetitle":"Classes/Test classes","data":{"unique title":"Entry:Classes/Test classes","title":"Test classes","class names":["Class 1","Class 2"]}},{"pagetitle":"Classes/Test sub-classes","data":{"unique title":"Entry:Classes/Test sub-classes","title":"Test sub-classes","class names":["Sub-class 1","Sub-class 2"]}},{"pagetitle":"Classes/Test sub-sub classes 1","data":{"unique title":"Entry:Classes/Test sub-sub classes_1","title":"Test sub-sub classes","class names":["Sub-sub class 1","Sub-sub class 2"]}},{"pagetitle":"Classes/School districts","data":{"unique title":"Entry:Classes/School districts","title":"School districts","class names":["School district 1","School district 2","School district 3"]}},{"pagetitle":"Classes/Schools","data":{"unique title":"Entry:Classes/Schools","title":"Schools","class names":["School 1","School 2","School 3","School 4"]}},{"pagetitle":"Classes/School classes","data":{"unique title":"Entry:Classes/School classes","title":"School classes","class names":["Class 1","Class 2","Class 3","Class 4","Class 5","Class 6","Class 7","Class 8","Class 9","Class 10"]}}]' -- Überprüfe, ob jsonData gültig ist if not jsonData or jsonData == '' then return "No JSON-Data received. <br/><br/>" end -- Debug: Gib die empfangenen JSON-Daten aus local debugInfo = "'''Received JSON Data: '''" .. tostring(jsonData) .. " <br/><br/>" -- Entferne führende und nachfolgende Leerzeichen jsonData = mw.text.trim(jsonData) -- Ersetze nicht druckbare Zeichen durch sichtbare Platzhalter für Debug-Zwecke local jsonDataVisible = jsonData:gsub("%c", function(c) return string.format("\\x%02X", string.byte(c)) end) debugInfo = debugInfo .. "'''Visible JSON Data: '''" .. jsonDataVisible .. " <br/><br/>" -- Entferne Platzhalter und unstrip -- jsonData = mw.text.killMarkers(jsonData) -- jsonData = mw.text.unstrip(jsonData) debugInfo = debugInfo .. "'''JSON Data Dump: '''" .. mw.dumpObject(jsonData) .. " <br/><br/>" -- Debug: Gib die bereinigten JSON-Daten aus debugInfo = debugInfo .. "'''Cleaned JSON Data: '''" .. jsonData .. " <br/><br/>" -- JSON-Daten in Lua-Tabelle umwandeln local success, json = pcall(mw.text.jsonDecode, jsonData) if not success then return debugInfo .. "'''Error decoding the JSON data: '''" .. tostring(json) end debugInfo = debugInfo .. "'''Decoded JSON Data: '''" .. mw.dumpObject(json) .. " <br/><br/>" 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, " <br/><br/>* ")) end return debugInfo .. table.concat(result, " <br/><br/>") end return p
Summary:
Please note that all contributions to Visual Data Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Json parameter test/doc
(
edit
)
Navigation menu
Personal tools
Log in
Dark mode
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Delete
Move
Purge
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information
VisualData
New article
Browse data