我需要为这个阵列中的每个人取得价值。
Array (
[0] => OrderItem Object (
[description:protected] => 0987654321
[unitPrice:protected] => 396.0000
[quantity:protected] => 1.00
[taxPercentage:protected] => 0.250000
[sku:protected] => 212
)
)
喜欢,我想退出0987654321或396.0000 =)
我该怎么办?
我正在使用付款解决方案并尝试解决此问题。
此代码:$order = $details->getOrderItems();
和print_r
将写出我发布的这个数组。
变量$details = $detailsResponse->getPaymentDetails();
函数getOrderItems如下所示:
public function getOrderItems() {
return $this->orderItems;
}
答案 0 :(得分:0)
课程有吸气剂,所以你可以试试这个:
- (void)viewDidLoad
{
[super viewDidLoad];
//setup the array controller
self.arrayController = [NSArrayController new];
[self.arrayController addObject:@{@"namef": @"Test1", @"namel": @"a"}];
[self.arrayController addObject:@{@"namef": @"Test2", @"namel": @"b"}];
[self.arrayController addObject:@{@"namef": @"Test3", @"namel": @"c"}];
[self.arrayController addObject:@{@"namef": @"Test4", @"namel": @"B"}];
//setup the table view column bindings and sorting
[[self.tableView tableColumnWithIdentifier:@"0"] bind:NSValueBinding toObject:self.arrayController withKeyPath:@"arrangedObjects.namef" options:nil];
[[self.tableView tableColumnWithIdentifier:@"0"] setSortDescriptorPrototype:[NSSortDescriptor sortDescriptorWithKey:@"namef" ascending:YES selector:@selector(caseInsensitiveCompare:)]];
[[self.tableView tableColumnWithIdentifier:@"1"] bind:NSValueBinding toObject:self.arrayController withKeyPath:@"arrangedObjects.namel" options:nil];
[[self.tableView tableColumnWithIdentifier:@"1"] setSortDescriptorPrototype:[NSSortDescriptor sortDescriptorWithKey:@"namel" ascending:YES selector:@selector(caseInsensitiveCompare:)]];
//Bind the array controller to the tableView
[self.tableView bind:NSContentBinding toObject:self.arrayController withKeyPath:@"arrangedObjects" options:nil];
[self.tableView bind:NSSelectionIndexesBinding toObject:self.arrayController withKeyPath:@"selectionIndexes" options:nil];
//setup sorting
[self.tableView setSortDescriptors:[NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey:@"namel" ascending:YES selector:@selector(caseInsensitiveCompare:)]]];
[self.arrayController bind:NSSortDescriptorsBinding toObject:self withKeyPath:@"sortDescriptors" options:nil];
[self.arrayController setAutomaticallyRearrangesObjects:YES];
}
您可以在此处查看全班: https://github.com/PaysonAktiebolag/api-integration-php/blob/master/lib/orderitem.php
答案 1 :(得分:0)
print_r()
显示OrderItem
对象的受保护属性。除非你创建一个公共函数来获取它们,否则你运气不好。
例如,如果您创建公共函数,如;
public function getProtected($varName) {
if( property_exists($this, $varName) ) {
return $this->$varName;
}
return NULL;
}
您将能够获得protected
个变量。这是一个快速演示:https://eval.in/318390
您无法拨打$obj->description
的原因是variable visibility。
如果您尝试访问protected
变量,则会看到以下错误:Fatal error: Cannot access protected property OrderItem::$description