Recently, this problem occurs when the strings returned from the server are compressed. The solution is as follows:
//// ViewController. m // extract the string /// Created by du jia on 14-5-8. // Copyright (c) June 2014 dujia. all rights reserved. // # import "ViewController. h "# import" LFCGzipUtillity. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any 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% C3 % 05% C3 % 81% 81% 11% 00 + % 08% C2 % b1j % C2 % B6 % 01F % 10% C2 % 9E % C2 % A0g % C3 % BF % 25% C2 % 99% 0F % 60% C3 % A3 % C3 % A4 % C2 % A0 % C2 % A4 % 1F % C3 % A5 % C3 % 88% C3 % A 9Km % C2 % B4 % C3 % A9C % 07ZL2% C3 % B6 % 01% C3 % 84% C3 % B2 % C2 % A5 + 0% 00% 00% "; // [request responseString]; NSLog (@ "% @", data1r); // decodes NSString * decode = [self StringDecode: data1r] for the first time; // convert to NSData * data = [decode dataUsingEncoding: NSISOLatin1StringEncoding]; // decompress NSData * data13 = [LFCGzipUtillity uncompressZippedData: data]; // NSString * str = [[NSString alloc] initWithData: data13 encoding: NSUTF8StringEncoding]; // decodes NSString * decode1 = [self StringDecode: str]; NSLog (@ "decode1 = % @", decode1);}-(NSString *) StringDecode :( NSString *) str {return [[str stringByReplacingOccurrencesOfString: @ "+" withString: @ ""] Authorization: NSUTF8StringEncoding];}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
Output:
Decode1 =/Test string
Code download: http://download.csdn.net/detail/qqmcy/7314665