Android Question Zip JSON? (and other)

KMatle

Expert
Licensed User
Longtime User
I would like to zip JSON strings (on my server) because it will reduce it's size to about 20%.

I've only seen a lib to do this, but only files which I don't like to use.

Are there any other solutions to zip/unzip strings/objects like JSON?
 

Informatix

Expert
Licensed User
Longtime User
You have to convert your JSON to an array of bytes and compress this array. Example :
B4X:
Dim JsonGen As JSONGenerator
JsonGen.Initialize(YourMap)
Dim ByteConvert As ByteConverter
Dim YourData() As Byte = ByteConvert.StringToBytes(JsonGen.ToString, "UTF-8")
Dim Compressor As CompressedStreams
Return Compressor.CompressBytes(YourData, "zlib")
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
if I read it right he wants it done on the server before downloading so he should use the php gzencode function.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
C'mon guys (including @Erel ). Of course IT IS B4A related.

I just forgot the word "B4A".

And even if not, it MUST be ok as long as it is related to a function I use via B4a or any other tool I have spend money for! I spend a lot of time to help others here, too without making comments like that.

There's no need to be sarcastic here. For the first time im a bit speechless. The most disturbing thing to me is your "like", Erel.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
C'mon guys (including @Erel ). Of course IT IS B4A related.

I just forgot the word "B4A".

And even if not, it MUST be ok as long as it is related to a function I use via B4a or any other tool I have spend money for! I spend a lot of time to help others here, too without making comments like that.

There's no need to be sarcastic here. For the first time im a bit speechless. The most disturbing thing to me is your "like", Erel.
??? There's nothing sarcastic here. If your question is related to B4A, then you have an answer in post #2. If your question is related to PHP, then it's not the right place in the forum. As I know that you know there's a "Chit chat" section for off-topic discussions, my first reaction was to think that your question was not related to PHP, but to B4A. Am I wrong ?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
@KMatle : is it on the device or on the php side that you want to compress the json?
My previous post has a hint to what you need if it is server-side so I don't get why you are upset.

B4X:
$gzdata = gzencode($json, 9);
$fp = fopen("library/data.gz", "w");
fwrite($fp, $gzdata);
fclose($fp);
 
Upvote 0
Top