]> git.sesse.net Git - vlc/commitdiff
generate properly escaped json
authorRob Jonson <rob@hobbyistsoftware.com>
Wed, 28 Sep 2011 12:05:15 +0000 (13:05 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 5 Oct 2011 16:50:49 +0000 (18:50 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
share/lua/http/requests/browse.json
share/lua/http/requests/playlist.json
share/lua/http/requests/status.json
share/lua/intf/modules/httprequests.lua

index da9fc9ac3a6697ca54fa1401099dd1915b9df196..39fb9b54d0109c880c399444f6dde1ae9877bde9 100644 (file)
@@ -33,8 +33,7 @@ httprequests.processcommands()
 
 local browseTable=httprequests.getbrowsetable()
 
-print('{')
-httprequests.printTableAsJson(browseTable,0)
-print('}')
+httprequests.printTableAsJson(browseTable)
+
 
 ?>
index f99866ec1ea5afb924431a580e9b781e717df982..7f531f3d7034aff45b91c697bf754f05b82fe31b 100644 (file)
@@ -31,8 +31,6 @@ require "httprequests"
 
 httprequests.processcommands()
 
-print('{')
-httprequests.printTableAsJson(httprequests.playlisttable(),0)
-print('}')
+httprequests.printTableAsJson(httprequests.playlisttable())
 
 ?>
index f98ed22cc922c2f47e56394dbce51b735b19938f..d44615865b592df1f34c2145c05d3ec7dc78af25 100644 (file)
@@ -33,8 +33,6 @@ httprequests.processcommands()
 
 local statusTable=httprequests.getstatus(true)
 
-print('{')
-httprequests.printTableAsJson(statusTable,0)
-print('}')
+httprequests.printTableAsJson(statusTable)
 
 ?>
index cd86113ae2ac30837dc8718a079ffad6e6319728..9e549c4a08d5048e0981b9ce5b00717d63d026bb 100644 (file)
@@ -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)