2

如何将此javascript数据转换为ios兼容数据并将其放入字典中,当我执行类似newCustomer [“cvc_check”]之类的操作时,我得到一个零,我试图从解析PFCloud.callFunctioninBackground中获取数据这是调用 stripe.com api 来获得这些结果

func hasToken(token: STPToken!) {

var parameters = ["cardToken":token.tokenId,
                  "objectId":PFUser.currentUser().objectId]

    PFCloud.callFunctionInBackground("createCustomer", withParameters:parameters) {
        (results: AnyObject!, error: NSError!) -> Void in
        if !error {

            var newCustomer = results as Dictionary<String, AnyObject>
            println(newCustomer["cvc_check"]) // This gives me a nil

            self.successfulPayment()
        } else {
            let message = error.userInfo["error"] as NSString
            self.hasError("\(message) Please try agains.")
        }
    }

我的截图

4

1 回答 1

0

我认为问题出在这条线上:

var newCustomer = results as Dictionary<String, AnyObject>

正如您在评论中所说,结果是一个Array,所以这一行应该是:

var newCustomer = results as Array<Dictionary<String, AnyObject>>

这有帮助吗?

于 2014-08-27T06:16:22.773 回答