luci-base: use serialize_json() in luci.http
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
61a9a58efc
commit
390c4bd5a7
1 changed files with 1 additions and 36 deletions
|
@ -285,40 +285,5 @@ urlencode = protocol.urlencode
|
||||||
--- Send the given data as JSON encoded string.
|
--- Send the given data as JSON encoded string.
|
||||||
-- @param data Data to send
|
-- @param data Data to send
|
||||||
function write_json(x)
|
function write_json(x)
|
||||||
if x == nil then
|
util.serialize_json(x, write)
|
||||||
write("null")
|
|
||||||
elseif type(x) == "table" then
|
|
||||||
local k, v
|
|
||||||
if type(next(x)) == "number" then
|
|
||||||
write("[ ")
|
|
||||||
for k, v in ipairs(x) do
|
|
||||||
write_json(v)
|
|
||||||
if next(x, k) then
|
|
||||||
write(", ")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
write(" ]")
|
|
||||||
else
|
|
||||||
write("{ ")
|
|
||||||
for k, v in pairs(x) do
|
|
||||||
write("%q: " % k)
|
|
||||||
write_json(v)
|
|
||||||
if next(x, k) then
|
|
||||||
write(", ")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
write(" }")
|
|
||||||
end
|
|
||||||
elseif type(x) == "number" or type(x) == "boolean" then
|
|
||||||
if (x ~= x) then
|
|
||||||
-- NaN is the only value that doesn't equal to itself.
|
|
||||||
write("Number.NaN")
|
|
||||||
else
|
|
||||||
write(tostring(x))
|
|
||||||
end
|
|
||||||
else
|
|
||||||
write('"%s"' % tostring(x):gsub('["%z\1-\31]', function(c)
|
|
||||||
return '\\u%04x' % c:byte(1)
|
|
||||||
end))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue