简体   繁体   中英

iPhone- \ character issue in JSON Parsing

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?

you can replace \\ with whitespace like:-

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

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

OUTPUT

hi hoowoer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM