OC 对ISO-8859-1编码格式的进行GZIP解压
2018-08-22 本文已影响0人
hope20
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