我目前正在 iOS 中使用 AddressBook,我正在从用户的所有联系人那里获取电子邮件,并将它们放入NSMutableArray
. 现在我必须将此数组传递给服务器[PHP]。但问题是电子邮件在双引号中,所以它看起来像这样:
(
"user@gmail.com",
"user2@gmail.com",
"user3@gmail.com"
)
那是我的代码:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
else { // we're on iOS 5 or older
accessGranted = YES;
}
if (accessGranted) {
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
_usersEmails = [[NSMutableArray alloc] initWithCapacity:CFArrayGetCount(people)];
for (CFIndex i = 0; i < CFArrayGetCount(people); i++) {
ABRecordRef person = CFArrayGetValueAtIndex(people, i);
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
for (CFIndex j=0; j < ABMultiValueGetCount(emails); j++) {
NSData* email = [(__bridge NSString*)ABMultiValueCopyValueAtIndex(emails, j) dataUsingEncoding:NSUTF8StringEncoding];
[_usersEmails addObject:email];
}
CFRelease(emails);
}
CFRelease(addressBook);
CFRelease(people);
实现服务器端的 Web 程序员告诉我,我必须传递不带双引号的字符串数组。
如何删除数组每个字符串中的双引号?
更新:
这是服务器接收到的实际数据:
\"user@gmail.com\"','\"user@gmail.com\"','\"user@gmail.com\"','\"user@me.com\"