3

I am using objective C JSON parsing library. My web service returns the JSON response. My parser fails as there is an '\' character in the response string. The response string is like ":\/\/68.491.5.780\/iphoneapplication" but I want to be like "://68.491.5.780/".

My code is here:

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];

So how can I remove all back slash "\" in the response receive from web service?

halfer
  • 19,824
  • 17
  • 99
  • 186
kumar Sudheer
  • 705
  • 3
  • 8
  • 28

1 Answers1

4

you can replace \ with whitespace like:-

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

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

OUTPUT

hi hoowoer

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144