gpt4 book ai didi

ios - Swift Alamofire 映射器

转载 作者:行者123 更新时间:2023-11-30 12:21:26 25 4
gpt4 key购买 nike

Swift Alamofire Mapper 不会将字符串数组映射为 null。

例如,我们有:

["first_item", "second_item", null]

当我使用 Alamofire Mapper 时,它返回空数组,如 -> [],当我们的服务响应如下时,如何处理数组中的空值?

谢谢!

最佳答案

最后我找到了如何计算这个:)我的模型如下:

    import ObjectMapper
struct DataItems: Mappable {

var rulesUrl: String?
var isAvailable: Bool?
var companyName: String?
var offers: [String]?

required init?(map: Map){}

func mapping(){
..... mapping
}
}

在这个模型中,当我想将我的responseString映射到这个模型时,如果在优惠中我们有来自服务器的类似[“offer_1”,“offer_2”,null]的东西,alamofire返回nil优惠。但之后我改变了报价:[String]?提供[字符串?]?然后它就如我想要的那样工作了:)现在它就像下面这样:

import ObjectMapper
struct DataItems: Mappable {

var rulesUrl: String?
var isAvailable: Bool?
var companyName: String?
var offers: [String?]?

required init?(map: Map){}

func mapping(){
..... mapping
}

}

我希望它可以帮助其他人。

关于ios - Swift Alamofire 映射器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44745898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com