我有一个实际调用asp.net Web服务的应用程序但是当我用&
传输数据时它停止工作。如下所示jsonString有first_name有“Pranav&”所以当这个阶段我调用服务并在asciistringencoding中转换它时会因为ascii转换它而产生错误
"Pranav &"
发现两个&符号后停止工作
NSString * jsonString = @"{"home_phone":"123","GroupId":"GP00000099","first_name":"Pranav &","city":"df","last_name":"Purohit","state":"sl","email":"pjp@gmail.com","member_Id":"GM00008513"}";
NSString * post = [[NSString alloc] initWithFormat:@"jsonText=%@", jsonString];
NSLog(@"%@",post);
NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString * postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://www.myweburl.com/mywebservice.asmx/mymethod"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
答案 0 :(得分:0)
我得到了答案,当您嵌入& 将其替换为 \ u0026