0
내 응용 프로그램은 서버에 JSON 페이로드를 제출해야
는, 서버가 형식과 같이 원하는 :JSON 형식과 목표 - C는
{
"recipient_emails" = ("[email protected]", "[email protected]");
}
:
{
"recipient_emails" :["[email protected]", "[email protected]"]
}
내가 만들 보일 수있다 모든 것은이 형식입니다
내가 제출 한 내용이 작동하지 않습니다. 이는 stmp 메일 서버의 서버 문제 또는 제출할 JSON의 형식인지 여부를 알 수 없습니다. 당신이 NSJSONSerialization
를 사용하는 경우, 걱정하지 마세요 생성 된 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);
}
jsonData를 NSDictionary로 다시 변환하여 출력하면 (두 번째 출력에 표시되는 내용) 편의상 괄호가 추가됩니까? – random
@random WYSNWYG ("당신이 보는 것은 당신이 얻는 것이 아닙니다"). 설명은 객체를 JSON과 다르게 표시합니다. 대신 생성 된 JSON ** 문자열 **을 출력하면 올바르게 표시됩니다. –
나는 우리 stmp 서버처럼 보입니다. 당신의 도움을 주셔서 대단히 감사합니다. – random