Когда я пытаюсь отправить JSON строка на сервер результат, кажется, так
«[» [email protected] » «[email protected]»]»
Как убрать начало и конец двойных кавычек.
Какую ошибку я делаю и почему так происходит?
Я хочу вывод, как
[ «[email protected]», «[email protected]»]
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];NSString *url = [NSString stringWithFormat:@"http://myurl........."];
NSArray *arrayOfStrings = @[@"[email protected]", @"[email protected]"];
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);
Задача ещё не решена.
Других решений пока нет …