Hi,
here is my problem which stopped me:
I have base64 gziped string waiting on remote server. Download is ok. I got string on device. The problem is converting it to readable text (aka json)
I made also win mobile version which already works. I used next function to decompress string:
which returns json for parsing.
(string which I got on both device is the same (tested also with telnet so there are no differences)
Now let's go back to b4a:
I tried with two methods, both returned the same result, string with two � chars between each char. Of course json parser cannot parse that. s2 is the final string
Correct string would be: [{"ServerName":"GAIA","Url":...
But I got in both versions: [��{��"��S��e��r��v��e��r��N��a��m��e��"��:��"��G��A��I��A��"��,��"��U��r��l��"��:...
(I tried also with different encodings but then return is in chinese chars)
Thnx, tomot
here is my problem which stopped me:
I have base64 gziped string waiting on remote server. Download is ok. I got string on device. The problem is converting it to readable text (aka json)
I made also win mobile version which already works. I used next function to decompress string:
B4X:
public static string Decompress(string s)
{
var bytes = Convert.FromBase64String(s);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
gs.CopyTo(mso);
}
return Encoding.Unicode.GetString(mso.ToArray(), 0, (int)mso.Length);
}
}
(string which I got on both device is the same (tested also with telnet so there are no differences)
Now let's go back to b4a:
I tried with two methods, both returned the same result, string with two � chars between each char. Of course json parser cannot parse that. s2 is the final string
B4X:
Dim decompressed() As Byte
Dim cs As CompressedStreams
Dim su As StringUtils
Dim s1 As String
Dim s2 As String
Dim b() As Byte
... ver 1
b = B64.DecodeStoB(s1)
decompressed = cs.DecompressBytes(b, "gzip")
s2 = BytesToString(decompressed, 0, decompressed.Length, "UTF8")
Log(s2)
... ver 2
b = su.DecodeBase64(s1)
s2 = BytesToString(y, 0, y.Length, "UTF8")
Log(s2)
But I got in both versions: [��{��"��S��e��r��v��e��r��N��a��m��e��"��:��"��G��A��I��A��"��,��"��U��r��l��"��:...
(I tried also with different encodings but then return is in chinese chars)
Thnx, tomot