我正在使用 PaypalSDK 将 paypal 支付方式添加到我正在开发的应用程序中,它已经在工作,当支付成功时,我收到了一个响应,我正在将其转换为 jsonObject 但我不知道如何解析它只是为了从响应中提取代码。这是我得到的回应
JSON: [AnyHashable("response"): {
code = "******************* -****************-**********************";
}, AnyHashable("response_type"): authorization_code, AnyHashable("client"): {
environment = sandbox;
"paypal_sdk_version" = "2.11.5";
platform = iOS;
"product_name" = "PayPal iOS SDK";
}]
这就是我的 payPalFuturePaymentViewController 方法:
func payPalFuturePaymentViewController(_ futurePaymentViewController: PayPalFuturePaymentViewController, didAuthorizeFuturePayment futurePaymentAuthorization: [AnyHashable: Any]) {
print("PayPal Future Payment Authorization Success!")
self.resultText = futurePaymentAuthorization.description
let jsonObject = JSON(futurePaymentAuthorization.description)
print("JSON: \(jsonObject)")
// send authorization to your server to get refresh token.
futurePaymentViewController.dismiss(animated: true, completion: { () -> Void in
var paypalPago = PagoItem(noTarjeta: "", fechaExp: "", cvc: "", token: "", tipo: "PayPal")
self.metodosPago.append(paypalPago)
self.saveMetodo()
let destViewController : UIViewController = self.storyboard!.instantiateViewController(withIdentifier: "pagosLlenos")
var vcArray = self.navigationController?.viewControllers
vcArray?.removeLast()
vcArray?.append(destViewController)
self.navigationController?.setViewControllers(vcArray!, animated: true)
})
}
所以我想做的是从响应中获取代码,将其放入一个变量中,然后将该变量包含在 paypalPago 项中:
var paypalPago = PagoItem(noTarjeta: "", fechaExp: "", cvc: "", token: PayPalCode, tipo: "PayPal")
任何有关如何解析此 json 并提取我需要的代码的帮助将不胜感激:)