Swift almofire objectmapper是否始终返回nil?尝试许多解决方案,但没有运气

Swift almofire objectmapper是否始终返回nil?尝试许多解决方案,但没有运气,swift,alamofire,Swift,Alamofire,这个响应来自服务器,我使用下面的类 对于映射,但它如何给我零?我用的是alamofire 4和 swift 3用于映射,我使用的是AlamofireObject映射器 **1)Using below method for mapping** let URL = "http://rest-api" Alamofire.request(URL , method: .post, parameters:

这个响应来自服务器,我使用下面的类 对于映射,但它如何给我零?我用的是alamofire 4和 swift 3用于映射,我使用的是AlamofireObject映射器

 **1)Using below method for mapping**

    let URL = "http://rest-api"
            Alamofire.request(URL , method: .post,
                                 parameters: parameter,
                                 encoding: JSONEncoding.default).responseObject
                { (response: DataResponse<MessageResponse>) in

                print(response)

                let messageResponse = response.result.value
                print(messageResponse)

            }



**2)response that coming from server**.




SUCCESS: {
    appVersion = "<null>";
    messageId = "<null>";
    messageRequest =     {
        actionViewBean = "<null>";
        articleViewBean = "<null>";
        cabBookingViewBean = "<null>";
        cabStatusViewBean = "<null>";
        cabViewBean = "<null>";
        cacheBean = "<null>";
        categoryViewBean = "<null>";
        cityViewBean = "<null>";
        clientViewBean = "<null>";
        codeViewBean = "<null>";
        customerViewBean = "<null>";
        employeeAvailabilityList = "<null>";
        employeeViewBean = "<null>";
        entitlementList = "<null>";
        genericViewBean = "<null>";
        imageViewBean = "<null>";
        locationViewBean = "<null>";
        messageViewBean = "<null>";
        notifyMessageViewBean = "<null>";
        orderViewBean = "<null>";
        paginationViewBean = "<null>";
        paymentViewBean = "<null>";
        productViewBean = "<null>";
        scheduleList = "<null>";
        scheduleViewBean = "<null>";
        searchViewBean = "<null>";
        shopViewBean = "<null>";
        templateViewBean = "<null>";
        userViewBean = "<null>";
    };
    messageResponse =     {
        articleList = "<null>";
        cabBookingList = "<null>";
        cabList = "<null>";
        cabStatusList = "<null>";
        cacheBean = "<null>";
        categoryList =         (
                        {
                cacheId = "<null>";
                categoryCode = SANDWICH;
                categoryId = 4;
                categoryName = Sandwiches;
                clientCode = "<null>";
                imageURL = "";
                shortDescription = Broodjes;
            },
                        {
                cacheId = "<null>";
                categoryCode = LAMACHUNWRAPS;
                categoryId = 5;
                categoryName = "Lahmachun & Wraps";
                clientCode = "<null>";
                imageURL = "";
                shortDescription = "Lahmachun & Wraps";
            },
                        {
                cacheId = "<null>";
                categoryCode = MENUS;
                categoryId = 6;
                categoryName = "Menu's";
                clientCode = "<null>";
                imageURL = "";
                shortDescription = "Menu's";
            },
                        {
                cacheId = "<null>";
                categoryCode = KAPSALONDISH;
                categoryId = 7;
                categoryName = "Kapsalon & Dish";
                clientCode = "<null>";
                imageURL = "";
                shortDescription = "Kapsalon & Schotel";
            },
                        {
                cacheId = "<null>";
                categoryCode = SEVERAL;
                categoryId = 8;
                categoryName = Several;
                clientCode = "<null>";
                imageURL = "";
                shortDescription = Diversen;
            }
        );
        cityList = "<null>";
        clientList = "<null>";
        codeList = "<null>";
        customerList = "<null>";
        employeeAvailabilityList = "<null>";
        employeeList = "<null>";
        entitlementList = "<null>";
        genericList = "<null>";
        imageList = "<null>";
        locationList = "<null>";
        messageList = "<null>";
        notifyMessageList = "<null>";
        orderList = "<null>";
        paymentList = "<null>";
        productList = "<null>";
        scheduleList = "<null>";
        shopList = "<null>";
        templateList = "<null>";
        userList = "<null>";
    };
    status = SUCCESS;
}
**1)使用以下方法进行映射**
让URL=”http://rest-api"
请求(URL,方法:.post,
参数:参数,
编码:JSONEncoding.default).responseObject
{(响应:DataResponse)在
打印(答复)
让messageResponse=response.result.value
打印(messageResponse)
}
**2) 来自服务器**的响应。
成功:{
appVersion=“”;
messageId=“”;
messageRequest={
actionViewBean=“”;
articleViewBean=“”;
cabBookingViewBean=“”;
cabStatusViewBean=“”;
菜豆=”;
cacheBean=“”;
categoryViewBean=“”;
城市视野=”;
clientViewBean=“”;
codeViewBean=“”;
customerViewBean=“”;
employeeAvailabilityList=“”;
employeeViewBean=“”;
权利列表=”;
genericViewBean=“”;
imageViewBean=“”;
locationViewBean=“”;
messageViewBean=“”;
notifyMessageViewBean=“”;
orderViewBean=“”;
paginationViewBean=“”;
paymentViewBean=“”;
productViewBean=“”;
scheduleList=“”;
scheduleViewBean=“”;
searchViewBean=“”;
shopViewBean=“”;
templateViewBean=“”;
userViewBean=“”;
};
messageResponse={
articleList=“”;
计程车登记表=”;
cabList=“”;
cabStatusList=“”;
cacheBean=“”;
类别列表=(
{
cacheId=“”;
类别代码=三明治;
类别ID=4;
categoryName=三明治;
clientCode=“”;
imageURL=“”;
shortDescription=fulljes;
},
{
cacheId=“”;
categoryCode=0;
类别ID=5;
categoryName=“Lahmachun&wrapps”;
clientCode=“”;
imageURL=“”;
shortDescription=“Lahmachun&wrapps”;
},
{
cacheId=“”;
类别代码=菜单;
类别ID=6;
categoryName=“菜单”;
clientCode=“”;
imageURL=“”;
shortDescription=“菜单”;
},
{
cacheId=“”;
categoryCode=卡普洛诺盘;
类别ID=7;
categoryName=“Kapsalon&Dish”;
clientCode=“”;
imageURL=“”;
shortDescription=“Kapsalon&Schotel”;
},
{
cacheId=“”;
类别代码=多个;
类别ID=8;
categoryName=多个;
clientCode=“”;
imageURL=“”;
shortDescription=Diversen;
}
);
城市列表=”;
clientList=“”;
代码列表=”;
customerList=“”;
employeeAvailabilityList=“”;
雇员名单=”;
权利列表=”;
genericList=“”;
imageList=“”;
locationList=“”;
messageList=“”;
notifyMessageList=“”;
订单列表=”;
paymentList=“”;
productList=“”;
scheduleList=“”;
购物清单=”;
templateList=“”;
用户列表=”;
};
状态=成功;
}
3)用于映射的类 3.1.1)消息响应

import Foundation
import ObjectMapper



public class MessageResponse : Mappable,BaseMappable {




    public var cacheBean : String?
    public var clientList : String?
    public var userList : String?
    public var entitlementList : String?
    public var cityList : String?
    public var locationList : String?
    public var categoryList : Array<CategoryList>?
    public var productList : String?
    public var templateList : String?
    public var customerList : String?
    public var codeList : String?
    public var notifyMessageList : String?
    public var imageList : String?
    public var orderList : String?
    public var shopList : String?
    public var messageList : String?
    public var employeeList : String?
    public var employeeAvailabilityList : String?
    public var scheduleList : String?
    public var paymentList : String?
    public var articleList : String?
    public var genericList : String?
    public var cabList : String?
    public var cabBookingList : String?
    public var cabStatusList : String?



    public func mapping(map: Map) {

        cacheBean <- map["cacheBean"]
        clientList <- map["clientList"]
        userList <- map["userList"]
        entitlementList <- map["entitlementList"]
        cityList <- map["cityList"]
        locationList <- map["locationList"]
         categoryList <- map["categoryList"]


        productList <- map["productList"]
        templateList <- map["templateList"]
        customerList <- map["customerList"]
        codeList <- map["codeList"]
        notifyMessageList <- map["notifyMessageList"]
        imageList <- map["imageList"]
        orderList <- map["orderList"]
        shopList <- map["shopList"]
        messageList <- map["messageList"]
        employeeList <- map["employeeList"]
        employeeAvailabilityList <- map["employeeAvailabilityList"]
        scheduleList <- map["scheduleList"]
        paymentList <- map["paymentList"]
        articleList <- map["articleList"]
        genericList <- map["genericList"]
        cabList <- map["cabList"]
        cabBookingList <- map["cabBookingList"]
        cabStatusList <- map["cabStatusList"]

    }


    public required init?(map: Map) {

    }



}
<代码>导入基础 导入对象映射器 公共类MessageResponse:可映射,可BaseMappable{ 公共变量cacheBean:String? public var clientList:String? 公共变量userList:String? 公共var授权列表:字符串? 公共变量cityList:字符串? 公共变量位置列表:字符串? 公共变量类别列表:数组? 公共变量productList:字符串? 公共var模板列表:字符串? 公共var客户列表:字符串? 公共变量代码列表:字符串? public var notifyMessageList:字符串? 公共变量imageList:字符串? 公共变量orderList:String? public-var-shopList:String? 公共var消息列表:字符串? 公共变量employeeList:字符串? 公共变量employeeAvailabilityList:字符串? 公共变量计划列表:字符串? 公共var paymentList:字符串? 公共var文章列表:字符串? 公共变量genericList:字符串? 公共列表:字符串? public var cabBookingList:字符串? 公共变量列表:字符串? 公共函数映射(映射:映射){
cacheBean您正在从服务器获取null。首先尝试修复该问题。categoryList呢?它不是null。这意味着我必须编写一个另一个顶级类?现在我能够获得响应,但它给我的错误是“NSArray元素未能匹配Swift数组元素类型”当我访问value.let category=response.result.value?.messageResponse?[“categoryList”]作为![CategoryViewBean]打印(类别[0].categoryName)您正在从服务器获取null。首先尝试修复该问题。categoryList呢?它不是null。这意味着我必须编写一个又一个顶级类?现在我能够获得响应,但它给我的错误是“NSArray元素未能匹配Swift数组元素类型”当我访问value.let category=response.result.value?message时
public class MessageRequest : Mappable {

    public var cacheBean : String?
    public var paginationViewBean : String?
    public var searchViewBean : String?
    public var actionViewBean : String?
    public var clientViewBean : String?
    public var userViewBean : String?
    public var entitlementList : String?
    public var categoryViewBean : String?
    public var productViewBean : String?
    public var templateViewBean : String?
    public var customerViewBean : String?
    public var cityViewBean : String?
    public var locationViewBean : String?
    public var codeViewBean : String?
    public var notifyMessageViewBean : String?
    public var imageViewBean : String?
    public var orderViewBean : String?
    public var shopViewBean : String?
    public var messageViewBean : String?
    public var employeeViewBean : String?
    public var employeeAvailabilityList : String?
    public var scheduleViewBean : String?
    public var scheduleList : String?
    public var paymentViewBean : String?
    public var articleViewBean : String?
    public var genericViewBean : String?
    public var cabViewBean : String?
    public var cabBookingViewBean : String?
    public var cabStatusViewBean : String?



    public required init?(map: Map) {


    }


    public func mapping(map: Map) {

        cacheBean <- map["cacheBean"]
        paginationViewBean <- map["paginationViewBean"]
        searchViewBean <- map["searchViewBean"]
        actionViewBean <- map["actionViewBean"]
        clientViewBean <- map["clientViewBean"]
        userViewBean <- map["userViewBean"]
        entitlementList <- map["entitlementList"]
        categoryViewBean <- map["categoryViewBean"]
        productViewBean <- map["productViewBean"]
        templateViewBean <- map["templateViewBean"]
        customerViewBean <- map["customerViewBean"]
        cityViewBean <- map["cityViewBean"]
        locationViewBean <- map["locationViewBean"]
        codeViewBean <- map["codeViewBean"]
        notifyMessageViewBean <- map["notifyMessageViewBean"]
        imageViewBean <- map["imageViewBean"]
        orderViewBean <- map["orderViewBean"]
        shopViewBean <- map["shopViewBean"]
        messageViewBean <- map["messageViewBean"]
        employeeViewBean <- map["employeeViewBean"]
        employeeAvailabilityList <- map["employeeAvailabilityList"]
        scheduleViewBean <- map["scheduleViewBean"]
        scheduleList <- map["scheduleList"]
        paymentViewBean <- map["paymentViewBean"]
        articleViewBean <- map["articleViewBean"]
        genericViewBean <- map["genericViewBean"]
        cabViewBean <- map["cabViewBean"]
        cabBookingViewBean <- map["cabBookingViewBean"]
        cabStatusViewBean <- map["cabStatusViewBean"]

    }




}
public class CategoryList : Mappable {

    public var categoryId : Int?
    public var clientCode : String?
    public var categoryCode : String?
    public var categoryName : String?
    public var cacheId : String?
    public var shortDescription : String?
    public var imageURL : String?


    required public init?(map: Map){

    }



    public func mapping(map: Map) {

        categoryId <- map["categoryId"]
        clientCode <- map["clientCode"]
        categoryCode <- map["categoryCode"]
        categoryName <- map["categoryName"]
        cacheId <- map["cacheId"]
        shortDescription <- map["shortDescription"]
        imageURL <- map["imageURL"]


    }




}