这是 NSDictionary 的输出:
{
client = {
environment = mock;
"paypal_sdk_version" = "1.0.3";
platform = iOS;
"product_name" = "PayPal iOS SDK";
};
payment = {
amount = "39.95";
"currency_code" = USD;
"short_description" = "Awesome saws";
};
"proof_of_payment" = {
"adaptive_payment" = {
"app_id" = "APP-1245783590";
"pay_key" = "AP-70M62356425642W";
"payment_exec_status" = COMPLETED;
timestamp = "2012-03-03T15:53:55Z";
};
};
它来自贝宝自适应支付。我最终这样做了:
- (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
NSDictionary *pOPDictionary = [NSDictionary dictionaryWithDictionary:completedPayment.confirmation];
NSLog(@"pOPDictionary: %@",pOPDictionary);
NSDictionary *subDictionary = [pOPDictionary objectForKey:@"proof_of_payment"];
NSDictionary *sub2Dictionary = [subDictionary objectForKey:@"adaptive_payment"];
NSString *proofString = [sub2Dictionary objectForKey:@"payment_exec_status"];
if ([proofString isEqualToString:@"COMPLETED"]) {
NSLog(@"Payment Completed Successfully");
} else {
NSLog(@"Payment Error");
}
NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation options:0 error:nil];
}
有没有更有效的方法从字典字典中获取该键?我只需要那把钥匙。所以我不认为我应该循环或循环通过其他人。