0
我收到一個作爲指向集合的指針發送的對象。 我可以直接作爲NSDictionary訪問字段。使用JSON對象索引到NSArray中
emails field
作爲一個數組發送,我用圓括號收到它。目前我通過我認爲是迂迴的方法獲得emailaddress
。 我怎樣才能最有效地到達電子郵件地址?
let allDoc = users.allDocuments[0]
print("allDoc: \(allDoc)")
let emailsArray = users.allDocuments[0].valueForKey("emails") as! NSArray
print("emailsArray: \(emailsArray)")
let emailAddress = emailsArray[0]["address"] as! String
print("emailAddress: \(emailAddress)")
控制檯輸出:
allDoc: <METDocument key: <collection: users, ID: kzzw3vcqukD62xEyz>, fields: {
emails = (
{
address = "[email protected]";
verified = 1;
}
);
profile = {
address = {
city = "";
country = nor;
lineOne = "";
lineTwo = "";
zip = "";
};
card = {
last4 = 4242;
verified = 1;
};
filledOut = 1;
name = {
first = XXXX;
last = XXXX;
};
phone = 9999999999;
validated = 1;
};
}>
emailsArray: (
{
address = "[email protected]";
verified = 1;
}
)
emailAddress: [email protected]
用打印'users.allDocuments [0]'的結果更新你的問題。 – rmaddy
@rmaddy我已更新 – KML
它是一個Meteor-iOS對象 – KML