我尝试使用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
如何在那里访问有效载荷?
答案 0 :(得分:0)
您需要使用开关来提取枚举的关联值。
switch decoded {
case .Success(let header, let payload, let signature, let signatureInput):
// do something with the values
case .Failure(let invalidToken):
// handle the failure
}