当我尝试将 JSON 字符串发送到服务器时,结果似乎是这样的
" [" sudheer@gmail.com"," venkat@gmail.com"]"
如何删除开始和结束双引号响应。
我在做什么错,为什么会这样?
我想输出
[" sudheer@gmail.com"," venkat@gmail.com"]
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *url = [NSString stringWithFormat:@"http://myurl........."];
NSArray *arrayOfStrings = @[@"sudheer@gmail.com", @"venkat@gmail.com"];
NSError *error = nil;
NSData *json;
NSString *jsonString;
if ([NSJSONSerialization isValidJSONObject:arrayOfStrings])
{
// Serialize the dictionary
json = [NSJSONSerialization dataWithJSONObject:arrayOfStrings options:NSJSONWritingPrettyPrinted error:&error];
// If no errors, let's view the JSON
if (json != nil && error == nil)
{
jsonString = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
NSLog(@"JSON: %@", jsonString);
//NSString *cleanedString=[jsonString stringByReplacingOccurrencesOfString:@"/"" withString:@""];
}
}
NSString *userId = [delegate.objectId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *projectId = [@"gcyn7uyUVh" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSMutableString* requestURL = [[NSMutableString alloc] initWithString:url];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: [NSString stringWithString:requestURL]]];
[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
//NSString *emails = [addSponsorEmailStringInModel componentsJoinedByString:@","];
[request setHTTPBody:[[NSString stringWithFormat:@"userid=%@&projectSponsor=%@&projectid=%@", userId,jsonString,projectId] dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
_addSponsorserverRplyString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
NSLog(@"add sponsor Response Is :%@",_addSponsorserverRplyString);