Android Question Zip JSON? (and other)

Discussion in 'Android Questions' started by KMatle, Jan 27, 2015.

  1. KMatle

    KMatle Expert Licensed 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?
     
  2. Informatix

    Informatix Expert Licensed User

    You have to convert your JSON to an array of bytes and compress this array. Example :
    Code:
    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")
     
    KMatle likes this.
  3. sorex

    sorex Expert Licensed User

    if I read it right he wants it done on the server before downloading so he should use the php gzencode function.
     
  4. Informatix

    Informatix Expert Licensed User

    You're probably right. On a B4A forum, I expect questions related to B4A.
     
    NJDude and Erel like this.
  5. KMatle

    KMatle Expert Licensed 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.
     
  6. Informatix

    Informatix Expert Licensed User

    ??? 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 ?
     
    NJDude likes this.
  7. sorex

    sorex Expert Licensed 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.

    Code:
    $gzdata = gzencode($json, 9);
    $fp = fopen(
    "library/data.gz""w");
    fwrite($fp, $gzdata);
    fclose($fp);
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice