0

我有一个实际调用 asp.net Web 服务的应用程序,但是当我用它传输数据时&它停止工作。像下面的 jsonString 有 first_name 有“Pranav &” 所以在这个阶段当我调用服务并在 asciistringencoding 中转换它时它会产生错误,因为 ascii 将它转换为

&quotPranav &&quot

找到两个&符号它停止工作

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

1 回答 1

0

我得到了答案,当您将其嵌入替换为\u0026

于 2012-10-29T09:11:58.743 回答