有没有办法在JSON字符串中发送一些特殊字符,如',"如果我尝试在 JSON 中发送这个字符,那么我无法获得成功响应。
这是代码:
NSMutableDictionary *dicWebServiceData = [[NSMutableDictionary alloc] init];
[dicWebServiceData setValue:@"Today's menu" forKey:@"description"];
NSString *strBulkData = [NSString stringWithFormat:@"bulk_data=[%@]",[dicWebService JSONRepresentation]];
strBulkData = [strBulkData stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSData *postData = [strBulkData dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",webServiceURL,strWebServiceName]];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"POST"];
[req setTimeoutInterval:6000];
[req setValue:[NSString stringWithFormat:@"%d", postData.length] forHTTPHeaderField:@"Content-Length"];
[req setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req setHTTPBody:postData];
有没有办法在 JSON 中传递这个字符?谢谢,