美文网首页
OC 对ISO-8859-1编码格式的进行GZIP解压

OC 对ISO-8859-1编码格式的进行GZIP解压

作者: hope20 | 来源:发表于2018-08-22 16:02 被阅读0次
        NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:4];
        NSStringEncoding enc=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin1);
        NSData *testData = [responseStr dataUsingEncoding:enc];
        NSData *aesDe = [LFCGzipUtility ungzipData:testData];
        NSDictionary *dict = [NSDictionary objectFromJSONString:[[NSString alloc] initWithData:aesDe encoding:NSUTF8StringEncoding]];
    

    安卓代码如下

                       byte[] bytes = s.getBytes("ISO-8859-1");
            Log.d("CityRemoteDao", "解压前大小:"+bytes.length);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes));
            byte[] buffer = new byte[1024 * 5];
            int len = 0;
            while ((len = in.read(buffer)) > 0) {
                baos.write(buffer, 0, len);
            }
            bytes = baos.toByteArray();
            Log.d("CityRemoteDao", "解压后大小:"+bytes.length);
            s = new String(bytes, "UTF-8");
    

    这里要注意:
    1、导入类 LFCGzipUtility.h 这个是别人写好的 类似于安卓GZIPInputStream吧

    2、上述LFCGzipUtility类需要 导入libz.dylib / libz.tbd ( for iOS9.0 or later )

    LFCGzipUtility下载地址: http://download.csdn.net/detail/lixianyue1991/9833170

    相关文章

      网友评论

          本文标题:OC 对ISO-8859-1编码格式的进行GZIP解压

          本文链接:https://www.haomeiwen.com/subject/aqhfiftx.html