'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)' with alamofire swift3

前端 未结 1 1188
日久生厌
日久生厌 2021-01-02 16:21

I\'ve encountered following error while uploading Swift3 using XCode8.

\'NSInvalidArgumentException\', reason: \'Invalid type in JSON write (_SwiftV

1条回答
  •  孤城傲影
    2021-01-02 16:53

    First of all in Swift 3 the Objective-C equivalent of id is Any rather than AnyObject, that avoids also the AnyObject castings.

    The error message indicates that an illegal type is used (Parameters), JSON supports only string, number, and array / dictionary.

    In your case the dictionary is [String:String], a type annotation is not needed at all

    let param = [
        "email" : txrNRC.text,
        "password" : txtPassword.text
    ]
    

    If txrNRC and txtPassword are optionals you need to unwrap them or use the nil coalescing operator to assign a placeholder if the value is nil

    0 讨论(0)
提交回复
热议问题