Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1109: | Строка 1109: | ||
return keys[1] | return keys[1] | ||
end | |||
local function is_array_of_primitives(tbl) | |||
if type(tbl) ~= "table" or not is_array(tbl) then | |||
return false | |||
end | |||
for _, v in ipairs(tbl) do | |||
if type(v) == "table" then | |||
return false | |||
end | |||
end | |||
return true | |||
end | end | ||
| Строка 1167: | Строка 1181: | ||
if k == idKey then | if k == idKey then | ||
if type(v) == "table" then | if type(v) == "table" then | ||
if | if is_array_of_primitives(v) then | ||
local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | local okJson, jsonVal = pcall(mw.text.jsonEncode, v) | ||
if okJson and jsonVal then | if okJson and jsonVal then | ||
parts[#parts + 1] = "value=" .. to_nowiki(jsonVal) | parts[#parts + 1] = "value=" .. to_nowiki(jsonVal) | ||
end | end | ||
end | |||
if next(v) ~= nil then | |||
append_table_tree(parts, k, v) | append_table_tree(parts, k, v) | ||
end | end | ||