繁体   English   中英

AlamofireJson / EVReflection-NSArray元素无法与以下中的Swift Array Element类型匹配

[英]AlamofireJson/EVReflection - NSArray element failed to match the Swift Array Element type in

还问这个问题作为项目GitHub中的错误: https : //github.com/evermeer/AlamofireJsonToObjects/issues/24

使用框架:Alamofire(用于REST)AlamofireJsonToObjects(用于反序列化JSON)(依赖于EVReflection)

尝试在对象中获取对象数组以进行反序列化时遇到问题。 输出显示fatal error: NSArray element failed to match the Swift Array Element type ,然后调试器在EVReflection.swift mi = Mirror(reflecting: theValue)第560行中断,错误为: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)

当嵌套对象不在数组中时,它能够反序列化嵌套对象,因此不确定在这里可能出什么问题。 我将在下面粘贴一些代码,以便您可以看到我的过程。

Alamofire请求,当我要求它打印debugDescription时发生错误

Alamofire.request(.GET, "http://server.com/api/get/all", headers: getAuthenticationHeaders()).
validate().
responseArray { (response: Result<[MyPrimaryObject], NSError>) in
       if(response.isSuccess){
           print(response.debugDescription)
           success(response.value)
       }
       if(response.isFailure){
           let error : NSError = response.error!
           NSLog("API failure: \(error.debugDescription)")
           failure(error)
       }
   }

楷模:

public class MyPrimaryObject : EVObject{

    public var myPrimaryObjectId : NSUUID?
    public var name : String = ""
    public var myObjectDescription: String?

    public var numberOfOccurrences : Int = 0
    public var positiveResponsePercentage : Float = 0

    public var secondaryObjects : [MySecondaryObject]?

    override public func propertyMapping() -> [(String?, String?)] {
        return [("myObjectDescription","Description")]

    }
}

public class MySecondaryObject : EVObject {
    public var mySecondaryObjectId : Int = 0
    public var dateRecorded : NSDate?
    public var rating : Int = 0
    public var userRemarks : String?
}

还应注意,当API响应中的secondaryObjects为null时,将完美解析MyPrimaryObject

我显然已经简化了,很高兴与您私下分享实际的代码。 任何帮助将不胜感激! 非常感谢!

正如我在https://github.com/evermeer/AlamofireJsonToObjects/issues/24中报道的那样

问题是,当您有一个子对象数组时,pascal大小写转换无法获得正确的类型。 因此,将字典放入数组中,您将得到错误。

该修复程序已在EVReflection 2.38.3中发布

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM