0

The string which is decompressed by zlib and been printed to log is in the format of below.

 {\x22uid\x22:\x22CE57134D17B57E873D7E7434E0E21783\x22.............2\x5Cu0000\x5Cu0000\x22,\x22http://tgs.7477.com/adiframe/ky/01/index.html\x5Cu0000\x5Cu0000\x22,\x22http://s.csbew.com/acookie.html\x5Cu0000\x5Cu0000\x22],\x22ver\x22:\x221\x22}\x0A200

How to encode the decompressed str so that it displays without something like '\xxx \u000' in lua?

newbie
  • 301
  • 4
  • 17
  • 1
    It's not clear what you mean by "looks like normal". It's also not clear on what that blob of text means. – Nicol Bolas Jul 05 '17 at 15:50
  • 2
    It does look quite normal already, with only double quotes sign escaped as \x22. Full text would be `"uid:CE57134D17B57E873D7E7434E0E21783"`. That hex doesn't require any further decoding because it's some unique id. – Vlad Jul 05 '17 at 17:07
  • I re-edit the question, hope this time it will make it clear. – newbie Jul 06 '17 at 01:35

1 Answers1

0

Try this unescape function to get characters from the hexadecimal representation:

    function unescape (s)
        s = string.gsub(s or '', "\\x(%x%x)", function (h) return string.char(tonumber(h,16)) end)
        return s
    end


    local str = [[{\x22uid\x22:\x22CE57134D17B57E873D7E7434E0E21783\x22.............2\x5Cu0000\x5Cu0000\x22,\x22http://tgs.7477.com/adiframe/ky/01/index.html\x5Cu0000\x5Cu0000\x22,\x22http://s.csbew.com/acookie.html\x5Cu0000\x5Cu0000\x22],\x22ver\x22:\x221\x22}\x0A200 ]]
    print( unescape(str) )

Result:

 {"uid":"CE57134D17B57E873D7E7434E0E21783".............2\u0000\u0000","http://tgs.7477.com/adiframe/ky/01/index.html\u0000\u0000","http://s.csbew.com/acookie.html\u0000\u0000"],"ver":"1"}
200 
Mike V.
  • 2,077
  • 8
  • 19