Commit 35cb1ed0 authored by Rob Jonson's avatar Rob Jonson Committed by Jean-Baptiste Kempf

generate properly escaped json

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 514b0244
...@@ -33,8 +33,7 @@ httprequests.processcommands() ...@@ -33,8 +33,7 @@ httprequests.processcommands()
local browseTable=httprequests.getbrowsetable() local browseTable=httprequests.getbrowsetable()
print('{') httprequests.printTableAsJson(browseTable)
httprequests.printTableAsJson(browseTable,0)
print('}')
?> ?>
...@@ -31,8 +31,6 @@ require "httprequests" ...@@ -31,8 +31,6 @@ require "httprequests"
httprequests.processcommands() httprequests.processcommands()
print('{') httprequests.printTableAsJson(httprequests.playlisttable())
httprequests.printTableAsJson(httprequests.playlisttable(),0)
print('}')
?> ?>
...@@ -33,8 +33,6 @@ httprequests.processcommands() ...@@ -33,8 +33,6 @@ httprequests.processcommands()
local statusTable=httprequests.getstatus(true) local statusTable=httprequests.getstatus(true)
print('{') httprequests.printTableAsJson(statusTable)
httprequests.printTableAsJson(statusTable,0)
print('}')
?> ?>
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
module("httprequests",package.seeall) module("httprequests",package.seeall)
local dkjson = require ("dkjson")
...@@ -195,47 +196,11 @@ function xmlString(s) ...@@ -195,47 +196,11 @@ function xmlString(s)
end end
end end
local printJsonKeyValue = function (k,v,indent)
print("\n")
for i=1,indent do print(" ") end
if (k) then
print("\""..k.."\":")
end
if (type(v)=="number") then
print(xmlString(v))
elseif (type(v)=="table") then
if (v._array==NULL) then
print("{\n")
printTableAsJson(v,indent+2)
print("\n}")
else
print("[")
printArrayAsJson(v._array,indent+2)
print("\n]")
end
else
print("\""..xmlString(v).."\"")
end
end
printTableAsJson = function (dict)
printArrayAsJson = function(array,indent) local output=dkjson.encode (dict, { indent = true })
first=true print(output)
for i,v in ipairs(array) do
if not first then print(",") end
printJsonKeyValue(NULL,v,indent)
first=false
end
end
printTableAsJson = function (dict,indent)
first=true
for k,v in pairs(dict) do
if not first then print(",") end
printJsonKeyValue(k,v,indent)
first=false
end
end end
local printXmlKeyValue = function (k,v,indent) local printXmlKeyValue = function (k,v,indent)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment