加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

通讯录下载(恢复数据到手机上面)

发布时间:2020-12-17 01:00:31 所属栏目:安全 来源:网络整理
导读:遍历从webservice,服务器上面的json文件中数据 ---解析json字符串---: -( void )parseJsonKit:( NSString *)jsonString { ? ? NSArray *array=[jsonString objectFromJSONString ]; ?? ? ? ? NSLog ( @"yunPanCounts=%d" ,[array count ]); ? ? // 云端联

遍历从webservice,服务器上面的json文件中数据

---解析json字符串---:


-(void)parseJsonKit:(NSString *)jsonString

{

? ? NSArray *array=[jsonStringobjectFromJSONString];

?? ?

? ?NSLog(@"yunPanCounts=%d",[arraycount]);

? ?//云端联系人的数量

? ? self.yunpanCounts.text =[NSStringstringWithFormat:@"%u",[arraycount]];


? ? for (int i =0; i< array.count; i++) {

?? ? ? ?

? ? ? ? NSDictionary* temp = [arrayobjectAtIndex:i];

?? ? ? ?

? ? ? ? NSString *firtname = [tempobjectForKey:@"firstname"];

? ? ? ? NSString *lastname = [tempobjectForKey:@"lastname"];

? ? ? ? NSString *middleName = [tempobjectForKey:@"middleName"];

? ? ? ? NSString *prefix = [tempobjectForKey:@"prefix"];

? ? ? ? NSString *suffix = [tempobjectForKey:@"suffix"];

? ? ? ? NSString *firstnamePhonetic? = [tempobjectForKey:@"firstnamePhonetic"];

? ? ? ? NSString *lastnamePhonetic = [tempobjectForKey:@"lastnamePhonetic"];

? ? ? ?

? ? ? ? NSString *organization = [tempobjectForKey:@"organization"];

? ? ? ? NSString *jobtitle = [tempobjectForKey:@"jobtitle"];

? ? ? ? NSString *department = [tempobjectForKey:@"department"];

? ? ? ? NSString *note = [tempobjectForKey:@"note"];

? ? ? ? NSString *birthday = [tempobjectForKey:@"birthday"];

? ? ? ? NSString *firstKnow = [tempobjectForKey:@"firstKnow"];

? ? ? ? NSString *lastKnow = [tempobjectForKey:@"lastKnow"];

?? ? ? ?

?? ? ? ?

? ? ? ?//add to contact

? ? ? ? ABAddressBookRef iphoneAddressBook =ABAddressBookCreate();

? ? ? ? ABRecordRef newPerson =ABPersonCreate();

? ? ? ? CFErrorRef error =NULL;

?? ? ? ?

? ? ? ? ABRecordSetValue(newPerson,kABPersonFirstNameProperty,firtname,&error);

? ? ? ? ABRecordSetValue(newPerson,kABPersonLastNameProperty,lastname,kABPersonMiddleNameProperty,middleName,kABPersonPrefixProperty,prefix,kABPersonSuffixProperty,suffix,kABPersonFirstNamePhoneticProperty,firstnamePhonetic,kABPersonLastNamePhoneticProperty,lastnamePhonetic,kABPersonOrganizationProperty,organization,kABPersonJobTitleProperty,jobtitle,kABPersonDepartmentProperty,department,kABPersonNoteProperty,note,kABPersonBirthdayProperty,birthday,&error);

?? ? ? ?

?? ? ? ?

? ? ? ? ABRecordSetValue(newPerson,kABPersonCreationDateProperty,firstKnow,kABPersonModificationDateProperty,lastKnow,&error);

?? ? ? ?

///////////////////特别值的注意的是多值字段的遍历///////////////////////////////

? ? ? ?//用于存放具有多个值的项

? ? ? ?ABMutableMultiValueRef multi =ABMultiValueCreateMutable(kABMultiStringPropertyType);

? ? ? ? //得到多值字段[电话号码]的集合? ? ??

? ? ? ? NSMutableDictionary *phoneDict = [tempobjectForKey:@"phone"];

? ? ? ? NSLog(@"%@",phoneDict);


? ? ? ? for (id keyin phoneDict)?

? ? ? ? {

? ? ? ? ? ? if ([keyisEqualToString:@"home"]) {

?? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,[phoneDict objectForKey:key],kABPersonHomePageLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"main"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneMainLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"work fax"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneWorkFAXLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? //other

?? ? ? ? ? ?

? ? ? ? ? ? if ([keyisEqualToString:@"mobile"]) {

?? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneMobileLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"home fax"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneHomeFAXLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"other fax"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneOtherFAXLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"pager"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhonePagerLabel,NULL);

? ? ? ? ? ? }

? ? ? ? ? ? if ([keyisEqualToString:@"iPhone"]) {

? ? ? ? ? ? ? ? ABMultiValueAddValueAndLabel(multi,kABPersonPhoneIPhoneLabel,NULL);

? ? ? ? ? ? }

?? ? ? ? ? ?

? ? ? ? ? ? ABRecordSetValue(newPerson,kABPersonPhoneProperty,multi,&error);

?? ? ? ? ? ?

? ? ? ? }

?? ? ? ?

? ? ? ?//清空该变量用于存放下一个多值的项

? ? ? ? multi = nil;

? ? ////////////////////////////////////////////////////////////////////////////////? ? ? ?

? ? ? ? ABAddressBookAddRecord(iphoneAddressBook,newPerson,&error);

? ? ? ? ABAddressBookSave(iphoneAddressBook,&error);

?? ? ? ?

? ? ? ? if (error!=NULL) {

? ? ? ? ? ?NSLog(@"Danger will Robinson! Danger!!!");

? ? ? ? }

?? ? ?

?? ? ? ?

? ? ? ? CFRelease(newPerson);

? ? ? ? CFRelease(iphoneAddressBook);

?? ? ? ?

?? ? ? ?

? ? }

?? ?

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读