【问题标题】:JWT 'DecodeResult' does not have a member named 'Success'JWT 'DecodeResult' 没有名为 'Success' 的成员
【发布时间】:2015-09-11 04:45:21
【问题描述】:

我正在尝试使用Swift JWT pod 来解码JWT 令牌。

// Get and decode the response
    var response = NSURLConnection.sendSynchronousRequest(request, returningResponse: AutoreleasingUnsafeMutablePointer<NSURLResponse?>(), error: NSErrorPointer())
    let responseContent = NSString(data:response!, encoding:NSUTF8StringEncoding)

    let decoded = JWT.decode(responseContent! as String, .HS256(secret))

    println(decoded.Success)

此代码给出错误:

'DecodeResult' does not have a member named 'Success'

看起来 DecodedResult 有一个 Enum: https://github.com/kylef/JSONWebToken.swift/blob/master/JWT/Decode.swift#L50

我如何才能访问那里的有效负载?

【问题讨论】:

    标签: ios swift jwt


    【解决方案1】:

    您需要使用开关来提取枚举的关联值。

    switch decoded {
    case .Success(let header, let payload, let signature, let signatureInput):
        // do something with the values
    case .Failure(let invalidToken):
        // handle the failure
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2014-11-09
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2013-05-23
      相关资源
      最近更新 更多