3

我正在使用目标 C JSON 解析库。我的 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 回答