Mr.KLD Mr.KLD - 24 days ago 17
JSON Question

Swift: iOS Paypal response parsing into NSDictionary/NSArray

I'm using PayPal sdk with Xcode for iOS

I managed to work with it successfully. Now, I have the following response from the server:

Code:

self.resultText = completedPayment.confirmation
println(self.resultText)


Result:

[response: {
"create_time" = "2015-07-13T17:52:31Z";
id = "PAY-NONETWORKPAYIDEXAMPLE123";
intent = sale;
state = approved;
},

client: {
environment = mock;
"paypal_sdk_version" = "2.11.1";
platform = iOS;
"product_name" = "PayPal iOS SDK";
},

response_type: payment]


My question is that, I just want to parse and access all the data results into NSDictionary and/or NSArray

Answer

I just solved it in this way...

let paymentResultDic = completedPayment.confirmation as NSDictionary


        let dicResponse: AnyObject? = paymentResultDic.objectForKey("response")
        println(dicResponse!.objectForKey("create_time"))
        println(dicResponse!.objectForKey("id"))
        println(dicResponse!.objectForKey("intent"))
        println(dicResponse!.objectForKey("state"))

        let dicClient: AnyObject? = paymentResultDic.objectForKey("client")
        println(dicClient!.objectForKey("environment"))
        println(dicClient!.objectForKey("paypal_sdk_version"))
        println(dicClient!.objectForKey("platform"))
        println(dicClient!.objectForKey("product_name"))

        println(paymentResultDic.objectForKey("response_type"))

if anybody has better solution, lets share it...

Thanks

Comments