1

我正在阅读 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)

2013-07-15 19:03:46.962 numbex[2635:907] 电话:+972549454456 2013-07-15 19:03:46.964 numbex[2635:907] firstName:קופ\327\241א 我试图替换“\ " 使用以下代码:

  NSString *str  = [jsonStringt stringByReplacingOccurrences:@"\\" withString:@" "];

还有这个:

NSString *str  = [jsonStringt stringByReplacingOccurrencesOfString:@"\\" withString:@"#" options:0 range:NSMakeRange(0, jsonStringt.length)];

但没有任何工作可以请有人帮忙

谢谢

4

1 回答 1

0

好的,我找到了解决它的方法:我以这种方式将所有希伯来语字符转换为希伯来语 ASCII 1255 代码页:'א' 转换为 'e0' 等等所有字符,反之亦然,现在一切正常,我认为它的工作,但它的工作。

于 2013-07-18T05:13:43.863 回答