Monday, 26 August 2013

How to add special character like "'" in JSON

How to add special character like "'" in JSON

Is there any way to send some special character like ', " in JSON string,
If I try to send this character in JSON, then I am not able to get success
response.
Here is the code :
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];
Is there any way to pass this character in JSON ? Thanks,

No comments:

Post a Comment