私のアプリは JSON ペイロードをサーバーに送信する必要があります。サーバーは次のような形式を必要とします。
{
"recipient_emails" :["test@xyz.net", "user@xyz.com"]
}
私が作成できるように見えるのは、次の形式だけです。
{
"recipient_emails" = ("test@xyz.net", "user@xyz.com");
}
送信しようとしているものが機能しません。stmp メール サーバーのサーバーの問題なのか、送信している JSON の形式なのかわかりません。
jsonを作成する方法は次のとおりです。
//Grab the data (from NSManagedObject)
NSString *emailData = [[NSString alloc] initWithData:self.submissionRecipients encoding:NSUTF8StringEncoding];
//Extract all the separate email address
NSArray *emails = [emailData componentsSeparatedByString:@","];
//If there are some there (which should always be)
if (emails) {
NSError *error;
//Add the array to an NSDictionary with key and convert to JSON
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithObject:emails forKey:@"recipient_emails"] options:0 error:&error];
//Add json to HTTPRequest
[theRequest setHTTPBody:jsonData];
//Print out for debug purposes
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
NSLog(@"%@", dic);
}