1
即时阅读的iPhone地址簿和遇到奇怪的数据制动器我试图发送到服务器的检索代码的JSON是这样的:iPhone地址簿数据带有奇怪的字符在hebraw
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年7月15日19:03:46.964 numbex [2635:907]姓:קופ\ 327 \ 241א
2013-07-15 19:03:46.961 numbex[2635:907] lastName:(null)
2013年7月15日19 :03:46.962 numbex [2635:907]电话:+972549454456 2013-07-15 19:03:46.964 numbex [2635:907]名字:קופ\ 327 \ 241א 我试着用此代码来代替 “\”:
NSString *str = [jsonStringt stringByReplacingOccurrences:@"\\" withString:@" "];
这:
NSString *str = [jsonStringt stringByReplacingOccurrencesOfString:@"\\" withString:@"#" options:0 range:NSMakeRange(0, jsonStringt.length)];
,但没有什么工作 可以有人帮忙,请
感谢
此问题中的任何信息是否有帮助:http://stackoverflow.com/questions/720052/nslog-incorrect-encoding? –
这不太好,谢谢 –