[vlc-devel] [PATCH 6/7] use dkjson to generate properly escaped json
Rob Jonson
rob at hobbyistsoftware.com
Tue Sep 27 11:45:32 CEST 2011
---
share/lua/http/requests/browse.json | 5 +--
share/lua/http/requests/playlist.json | 4 +--
share/lua/http/requests/status.json | 4 +--
share/lua/intf/modules/httprequests.lua | 43 +++----------------------------
4 files changed, 8 insertions(+), 48 deletions(-)
diff --git a/share/lua/http/requests/browse.json b/share/lua/http/requests/browse.json
index da9fc9a..39fb9b5 100644
--- a/share/lua/http/requests/browse.json
+++ b/share/lua/http/requests/browse.json
@@ -33,8 +33,7 @@ httprequests.processcommands()
local browseTable=httprequests.getbrowsetable()
-print('{')
-httprequests.printTableAsJson(browseTable,0)
-print('}')
+httprequests.printTableAsJson(browseTable)
+
?>
diff --git a/share/lua/http/requests/playlist.json b/share/lua/http/requests/playlist.json
index f99866e..7f531f3 100644
--- a/share/lua/http/requests/playlist.json
+++ b/share/lua/http/requests/playlist.json
@@ -31,8 +31,6 @@ require "httprequests"
httprequests.processcommands()
-print('{')
-httprequests.printTableAsJson(httprequests.playlisttable(),0)
-print('}')
+httprequests.printTableAsJson(httprequests.playlisttable())
?>
diff --git a/share/lua/http/requests/status.json b/share/lua/http/requests/status.json
index f98ed22..d446158 100644
--- a/share/lua/http/requests/status.json
+++ b/share/lua/http/requests/status.json
@@ -33,8 +33,6 @@ httprequests.processcommands()
local statusTable=httprequests.getstatus(true)
-print('{')
-httprequests.printTableAsJson(statusTable,0)
-print('}')
+httprequests.printTableAsJson(statusTable)
?>
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index efe9300..3f513bb 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -24,6 +24,7 @@
module("httprequests",package.seeall)
+local dkjson = require ("dkjson")
@@ -195,47 +196,11 @@ function xmlString(s)
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
-
-printArrayAsJson = function(array,indent)
- first=true
- 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
+printTableAsJson = function (dict)
+ local output=dkjson.encode (dict, { indent = true })
+ print(output)
end
local printXmlKeyValue = function (k,v,indent)
--
1.7.5
More information about the vlc-devel
mailing list