JSONSerialization Invalid type in JSON write (_SwiftValue)

前端 未结 10 951
情书的邮戳
情书的邮戳 2020-12-14 14:14

Why does the following code give me the error:

Invalid type in JSON write (_SwiftValue).

The error is thrown on this line:

10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 14:38

    Just in case anyone is still having problems and is using Enums, another cause may be if you are passing an Enum value and not it's rawValue.

    Example:

    enum Status: String {
      case open
      case closed
    }
    

    instead of passing the enum:

    params = ["status": Status.open]
    

    pass

    params = ["status": Status.open.rawValue]
    

提交回复
热议问题