AlamofireObjectMapper 如何映射对象?
AlamofireObjectMapper how to map object?
这是我从 api
那里得到的回复
{
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-27T12:26:04.5809108+00:00";
email = "i9@gmail.com";
"first_name" = jack;
id = 10180;
"is_lock" = 0;
"last_name" = "<null>";
mobile = 9999999999;
password = e10adc3949ba59abbe56e057f20f883e;
"profile_Image" = "<null>";
status = PV;
subscription = 1;
updated = "2016-04-27T12:26:04.5809108+00:00";
"vendor_type_id" = 1;
};
Status = 1;}
现在我正在通过 alamofireObjectMapper 映射此响应
这是我的代码
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)
print(signupVarificationCode?.result)
if let threedayForecast = signupVarificationCode?.result {
for ResultNew in threedayForecast {
print(ResultNew)
}
}
}
这些是我的class,我在其中保存值
class signupVarificationCode: Mappable {
var Message : String?
var Status : String?
var result:[String:AnyObject]?
required init?(_ map: Map){
}
func mapping(map: Map) {
Message <- map["Message"]
Status <- map["Status"]
result <- map["Result"]
}
}
class Resultnew: Mappable
{
var lastName : String?
var isLock : String?
var mobile : String?
var id: String?
var attemptDate : String?
var Created : String?
var Updated : String?
var Subscription: String?
var vendor_type : String?
var profileimage : String?
var pharmacy : String?
var vsbuscription : String?
var email: String?
var status : String?
var vendor_typeId : String?
var FirstName : String?
var Password: String?
required init?(_ map: Map){
}
func mapping(map: Map) {
lastName <- map["last_name"]
mobile <- map["mobile"]
id <- map["id"]
isLock <- map["is_lock"]
attemptDate <- map["attempt_date"]
Created <- map["created"]
Updated <- map["updated"]
Subscription <- map["subscription"]
vendor_type <- map["V002_vendors_type"]
profileimage <- map["profile_Image"]
pharmacy <- map["V003_pharmacy"]
vsbuscription <- map["V010_subscription"]
email <- map["email"]
status <- map["status"]
vendor_typeId <- map["vendor_type_id"]
FirstName <- map["first_name"]
Password <- map["password"]
}
}
这里我在我的函数中获取值
for ResultNew in threedayForecast {
print(ResultNew)
}
但是这些山谷是这样来的
("last_name", <null>)
("mobile", 123456)
("is_lock", 0)
("attempt_date", <null>)
("created", 2016-04-27T12:32:20.6046072+00:00)
("updated", 2016-04-27T12:32:20.6046072+00:00)
("subscription", 1)
("V002_vendors_type", <null>)
("profile_Image", <null>)
("V003_pharmacy", [])
("V010_subscription", <null>)
("email", i10@gmail.com)
("status", PV)
("vendor_type_id", 1)
("first_name", jack)
("id", 10182)
("password", e10adc3949ba59abbe56e057f20f883e)
但我无法访问是这样的
打印(ResultNew.mobile)
那么我如何访问我想要的特定值access.like我只想在这些中输入密码所以怎么能做到这一点?
您指定 result
应该是字典 ([String:AnyObject]
),所以您得到了字典。尝试将其更改为:
var Message : String?
var Status : String?
var result:Resultnew? // <-- this line
这是我从 api
那里得到的回复{
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-27T12:26:04.5809108+00:00";
email = "i9@gmail.com";
"first_name" = jack;
id = 10180;
"is_lock" = 0;
"last_name" = "<null>";
mobile = 9999999999;
password = e10adc3949ba59abbe56e057f20f883e;
"profile_Image" = "<null>";
status = PV;
subscription = 1;
updated = "2016-04-27T12:26:04.5809108+00:00";
"vendor_type_id" = 1;
};
Status = 1;}
现在我正在通过 alamofireObjectMapper 映射此响应
这是我的代码
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)
print(signupVarificationCode?.result)
if let threedayForecast = signupVarificationCode?.result {
for ResultNew in threedayForecast {
print(ResultNew)
}
}
}
这些是我的class,我在其中保存值
class signupVarificationCode: Mappable {
var Message : String?
var Status : String?
var result:[String:AnyObject]?
required init?(_ map: Map){
}
func mapping(map: Map) {
Message <- map["Message"]
Status <- map["Status"]
result <- map["Result"]
}
}
class Resultnew: Mappable
{
var lastName : String?
var isLock : String?
var mobile : String?
var id: String?
var attemptDate : String?
var Created : String?
var Updated : String?
var Subscription: String?
var vendor_type : String?
var profileimage : String?
var pharmacy : String?
var vsbuscription : String?
var email: String?
var status : String?
var vendor_typeId : String?
var FirstName : String?
var Password: String?
required init?(_ map: Map){
}
func mapping(map: Map) {
lastName <- map["last_name"]
mobile <- map["mobile"]
id <- map["id"]
isLock <- map["is_lock"]
attemptDate <- map["attempt_date"]
Created <- map["created"]
Updated <- map["updated"]
Subscription <- map["subscription"]
vendor_type <- map["V002_vendors_type"]
profileimage <- map["profile_Image"]
pharmacy <- map["V003_pharmacy"]
vsbuscription <- map["V010_subscription"]
email <- map["email"]
status <- map["status"]
vendor_typeId <- map["vendor_type_id"]
FirstName <- map["first_name"]
Password <- map["password"]
}
}
这里我在我的函数中获取值
for ResultNew in threedayForecast {
print(ResultNew)
}
但是这些山谷是这样来的
("last_name", <null>)
("mobile", 123456)
("is_lock", 0)
("attempt_date", <null>)
("created", 2016-04-27T12:32:20.6046072+00:00)
("updated", 2016-04-27T12:32:20.6046072+00:00)
("subscription", 1)
("V002_vendors_type", <null>)
("profile_Image", <null>)
("V003_pharmacy", [])
("V010_subscription", <null>)
("email", i10@gmail.com)
("status", PV)
("vendor_type_id", 1)
("first_name", jack)
("id", 10182)
("password", e10adc3949ba59abbe56e057f20f883e)
但我无法访问是这样的 打印(ResultNew.mobile)
那么我如何访问我想要的特定值access.like我只想在这些中输入密码所以怎么能做到这一点?
您指定 result
应该是字典 ([String:AnyObject]
),所以您得到了字典。尝试将其更改为:
var Message : String?
var Status : String?
var result:Resultnew? // <-- this line