Recently encountered with such a problem, the string returned from the server is compressed. The workaround is documented below
viewcontroller.m//string Decompression////Created by du Jia Li on 14-5-8.//Copyright (c) 2014 du Jia Li. All rights reserved.//#import "ViewController.h" #import "LFCGzipUtillity.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload{[Super viewdidload];//do no additional setup after loading the View, typically from a nib. Test string nsstring* data1r = @ "%1f%c2%8b%08%00%00%00%00%00%00%00%05%c3%81%c3%81%11%00+%08%04%c2%b1j%c2%b6%01f%10%c2% 9e%c2%a0g%c3%bf%25%c2%99%60%0f%05%c3%a3%c3%a4%c2%a0%c2%a4%1f%c3%a5%c3%88%c3%a9km%c2%b4%c3%a9c%07zl2%c3%b6%01% c3%84%c3%b2%c2%a5+0%00%00%00:222 ";//[request responsestring]; NSLog (@ "%@", data1r); First decoding nsstring* decode = [self stringdecode:data1r]; Convert to NSData nsdata* data = [decode datausingencoding:nsisolatin1stringencoding]; Decompression nsdata* data13 = [lfcgziputillity uncompresszippeddata:data]; nsstring* str = [[NSString alloc] Initwithdata:data13 encoding:nsutf8stringencoding]; Decoding nsstring* deCode1 = [self stringdecode:str]; NSLog (@ "decode1 =%@", decode1);} -(NSString *) Stringdecode: (nsstring*) str{return [[str stringbyreplacingoccurrencesofstring:@ ' + ' withstring:@ ' "] Str Ingbyreplacingpercentescapesusingencoding:nsutf8stringencoding];} -(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Output:
decode1 =/ Test String
Code Download: http://download.csdn.net/detail/qqmcy/7314665