almofire objectmapper总是返回nil?尝试很多解决方案,但没有运气

时间:2017-05-04 07:37:32

标签: swift alamofire

此响应来自服务器,我正在使用以下类     用于映射,但有些它如何给我零?我正在使用alamofire 4和     swift 3用于映射我正在使用alamofireObjectMapper。

 **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;
}

3)用于映射的类      3.1.1)MessageResponse

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) {

    }



}

3.1.2)消息请求类

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"]

    }




}

3.1.3)categoryList类

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"]


    }




}

0 个答案:

没有答案