3

私はObjectiveCJSON解析ライブラリを使用しています。私のWebサービスはJSON応答を返します。応答文字列に「\」文字が含まれているため、パーサーが失敗します。応答文字列はのようです":\/\/68.491.5.780\/iphoneapplication"が、私はのようになりたいです"://68.491.5.780/"

私のコードはここにあります:

NSURL *url=[NSURL URLWithString:
  @"http:// url address/Accountservice/Security/ValidateAccess?accesscode=abcd&type=0"];

NSData *postData = 
  [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

では、Webサービスから受信した応答のすべての円記号 "\"を削除するにはどうすればよいですか?

4

1 に答える 1

4

次のように\を空白に置き換えることができます:-

NSString *str =[NSString stringWithFormat:@"%@",@" hi \ hoowoer"];

str = [str stringByReplacingOccurrencesOfString:@"\""
                                     withString:@""];
NSLog(@"==%@",str);

出力

こんにちはhoowoer

于 2013-02-20T05:27:24.283 に答える