iPhoneのアドレス帳を読んでいて、サーバーに送信しようとしているjsonを壊す奇妙なデータを取得しています」取得コードは次のとおりです。
CFErrorRef * error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);
for(int i = 0; i < numberOfPeople; i++)
{
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
// NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);
CFStringRef nameF = (CFStringRef)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* firstName = (__bridge_transfer NSString*)nameF;
CFStringRef nameL = (CFStringRef)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString* lastName = (__bridge_transfer NSString*)nameL;
// NSString* lastName = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);
// [lastName UTF8String];
// [firstName UTF8String];
// NSString* phone = nil;
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person,kABPersonPhoneProperty);
if (ABMultiValueGetCount(phoneNumbers) > 0) {
self.phone = (__bridge_transfer NSString*)
ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, 0);
theEmail = (__bridge_transfer NSString*)email;
// NSLog(@"theEmail:%@", theEmail);
}
else
{
self.phone = @"";
}
// get all email associated with this person
ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty) ;
// convert it to an array
CFArrayRef allEmails = ABMultiValueCopyArrayOfAllValues(emailProperty) ;
// add these emails to our initial array
[emails addObjectsFromArray: (__bridge NSArray *)allEmails] ;
NSLog(@"phone:%@",self.phone);
NSLog(@"firstName:%@",firstName);
NSLog(@"lastName:%@",lastName);
if (firstName == nil) {
firstName = @"";
}
if (lastName == nil) {
lastName = @"";
}
if (theEmail == nil) {
theEmail = @"";
}
sing.contactsDict = [[NSMutableDictionary alloc]init];
[sing.contactsDict setObject:firstName forKey:@"fname"];
[sing.contactsDict setObject:lastName forKey:@"lname"];
[sing.contactsDict setObject:self.phone forKey:@"phone"];
[sing.contactsDict setObject:theEmail forKey:@"emails"];
// NSLog(@"[sing.contactsDict description]--> %@",[sing.contactsDict description]);
[ContactsList addObject:sing.contactsDict];
}
NSLog すると、連絡先の名前が次のように表示されます:2013-07-15 19:03:46.964 numbex[2635:907] firstName:קופ\327\241א
2013-07-15 19:03:46.961 numbex[2635:907] lastName:(null)
私は "\ " このコードで:
NSString *str = [jsonStringt stringByReplacingOccurrences:@"\\" withString:@" "];
この:
NSString *str = [jsonStringt stringByReplacingOccurrencesOfString:@"\\" withString:@"#" options:0 range:NSMakeRange(0, jsonStringt.length)];
しかし、何も機能していません誰か助けてください
ありがとう