在我的應用程序中,我正在使用AlamofireObjectMapper進行映射。我第一次使用這個。這裏是我的回答,我是從API獲得如何在AlamofireObjectMapper中映射對象
{
Message = "email verification link has been sent to your email. please verify your account.";
Result = {
"V002_vendors_type" = "<null>";
"V003_pharmacy" =();
"V010_subscription" = "<null>";
"attempt_date" = "<null>";
created = "2016-04-26T11:07:30.3192745+00:00";
email = "[email protected]";
"first_name" = abc;
id = 10167;
"is_lock" = 0;
"last_name" = "<null>";
mobile = 9999999999;
password = xxxxxxxxx;
"profile_Image" = "<null>";
status = PV;
subscription = 1;
updated = "2016-04-26T11:07:30.3192745+00:00";
"Fix_id" = 1;
};
Status = 1;
}
現在這是我的代碼
func pharmacySignUp()
{
let url = "http://\(basicURL)vendor_signup"
let param :[String : AnyObject] =
[
"email" : txtemail.text!,
"password" : txtpassword.text!,
"mobile" : txtmobile.text!,
"first_name" : txtname.text!
]
Alamofire.request(.POST, url, parameters: param, encoding: .JSON).responseObject { (response:Response<signupVarificationCode, NSError>) in
print(response.result.value)
let signupVarificationCode = response.result.value
print(signupVarificationCode)
print(signupVarificationCode!.Message)
print(signupVarificationCode?.status)
}
這就是我映射
class signupVarificationCode: Mappable {
var Message : String?
var status : String?
required init?(_ map: Map){
}
func mapping(map: Map) {
Message <- map["Message"]
status <- map["Status"]
}
}
做了一個類通過這段代碼,我可以得到消息,但現在我想映射結果對象,所以我該如何做到這一點?
感謝俞拉吉雙曲正弦它的工作,但我要訪問從結果對象中的所有變量,所以我讓這個對象
class Result: Mappable {
var lastName : String?
var mobile : String?
var id: String?
required init?(_ map: Map){
}
func mapping(map: Map) {
lastName <- map["last_name"]
mobile <- map["mobile"]
id <- map["id"]
}
}
我想在我的pharmacySignup方法來打印移動價值。所以我怎麼做到這一點?
謝謝哥們它的工作,但它給我一個完整的對象,但我想訪問諸如ID,密碼對象的所有變量,電子郵件,以便山楂我能做這個?? –
當你得到的對象,你再次做相同的價值,你需要例如:電子郵件=「[email protected]」;從數據中獲取字符串類型,如果讓emailID = result [「email」]爲?字符串{} –
爲「Id」例如//如果讓idValue = result [「id」] as?詮釋{///打印(idValue)} –