我需要从联系人 JSON 响应中提取数据
I need to extract data from contacts JSON response
我正在尝试从联系人中获取数据,我需要将其传递到 tableview,我已经获取了 firstName、LastName 和 phoneNumber。我得到一个 phone 数字的数组 我不知道如何从响应中获取特定的 phone 数字。请帮助我。
我把回复贴出来供大家参考。
[<CNContact: 0x155e8c1b0: identifier=DD78D98D-3ECD-4743-8FBB-AF67CC544BB7, givenName=S, familyName=Jerry Mom, organizationName=(null), phoneNumbers=(
"<CNLabeledValue: 0x280c8b200: identifier=10BB271D-611B-4D15-A452-BC553B79A9BF, label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x2816469c0: stringValue=+917904619229, initialCountryCode=(null)>>"
)
对一组联系人的响应,然后继续..
我需要从数组中单独取出这个数字 917904619229,我需要将它解析为标签。
我已经加载了 table 解析供您参考。
let contactsList = contacts[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2") as? contactListCell
cell?.profileName.text = contactsList.familyName
cell?.profileCountry.text = "\(contactsList.phoneNumbers)"
return cell!
}
通过使用这个 "\(contactsList.phoneNumbers)"
它将整个数组加载到标签中。
[<CNContact: 0x155e8c1b0: identifier=DD78D98D-3ECD-4743-8FBB-AF67CC544BB7, givenName=S, familyName=Jerry Mom, organizationName=(null), phoneNumbers=(
"<CNLabeledValue: 0x280c8b200: identifier=10BB271D-611B-4D15-A452-BC553B79A9BF, label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x2816469c0: stringValue=+91790989898984619229, initialCountryCode=(null)>>"
), 电子邮件地址=(
), postalAddresses=(not fetched)>, !$_, value=>"
), 电子邮件地址=(
), postalAddresses=(未获取)>, >"
), 电子邮件地址=(
), postalAddresses=(未获取)>, >"
), 电子邮件地址=(
), postalAddresses=(未获取)>, >"
)
像这样将您作为 json 发布的内容试试这个!!
{
familyName = "Jerry Mom";
organizationName = nil;
phoneNumbers = (
{
initialCountryCode = "IN ";
"stringValue" = "+917904619229 ";
}
);
}
for phoneNumber in phoneNumbers {
if let phoneValue = phoneNumber.object(forKey: "stringValue") as? String {
print(phoneValue)
}
}
或
for phone in contact.phoneNumbers {
if let phonValue = phone.value as? CNPhoneNumber {
print(phonValue.stringValue)
}
}
我正在尝试从联系人中获取数据,我需要将其传递到 tableview,我已经获取了 firstName、LastName 和 phoneNumber。我得到一个 phone 数字的数组 我不知道如何从响应中获取特定的 phone 数字。请帮助我。
我把回复贴出来供大家参考。
[<CNContact: 0x155e8c1b0: identifier=DD78D98D-3ECD-4743-8FBB-AF67CC544BB7, givenName=S, familyName=Jerry Mom, organizationName=(null), phoneNumbers=(
"<CNLabeledValue: 0x280c8b200: identifier=10BB271D-611B-4D15-A452-BC553B79A9BF, label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x2816469c0: stringValue=+917904619229, initialCountryCode=(null)>>"
) 对一组联系人的响应,然后继续.. 我需要从数组中单独取出这个数字 917904619229,我需要将它解析为标签。
我已经加载了 table 解析供您参考。
let contactsList = contacts[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2") as? contactListCell
cell?.profileName.text = contactsList.familyName
cell?.profileCountry.text = "\(contactsList.phoneNumbers)"
return cell!
}
通过使用这个 "\(contactsList.phoneNumbers)"
它将整个数组加载到标签中。
[<CNContact: 0x155e8c1b0: identifier=DD78D98D-3ECD-4743-8FBB-AF67CC544BB7, givenName=S, familyName=Jerry Mom, organizationName=(null), phoneNumbers=(
"<CNLabeledValue: 0x280c8b200: identifier=10BB271D-611B-4D15-A452-BC553B79A9BF, label=_$!<Mobile>!$_, value=<CNPhoneNumber: 0x2816469c0: stringValue=+91790989898984619229, initialCountryCode=(null)>>"
), 电子邮件地址=( ), postalAddresses=(not fetched)>, !$_, value=>" ), 电子邮件地址=( ), postalAddresses=(未获取)>, >" ), 电子邮件地址=( ), postalAddresses=(未获取)>, >" ), 电子邮件地址=( ), postalAddresses=(未获取)>, >" )
像这样将您作为 json 发布的内容试试这个!!
{
familyName = "Jerry Mom";
organizationName = nil;
phoneNumbers = (
{
initialCountryCode = "IN ";
"stringValue" = "+917904619229 ";
}
);
}
for phoneNumber in phoneNumbers {
if let phoneValue = phoneNumber.object(forKey: "stringValue") as? String {
print(phoneValue)
}
}
或
for phone in contact.phoneNumbers {
if let phonValue = phone.value as? CNPhoneNumber {
print(phonValue.stringValue)
}
}