我通过affiliateservice api获取TransactionList。 我的print_r($ response)给了我这个(我必须放xx,但实际上有数字):
stdClass Object
(
[getTransactionListReturn] => Array
(
[0] => stdClass Object
(
[iId] => xx
[sStatus] => pending
[sType] => normal
[sIp] => xx
[bPaid] => xx
[iPaymentId] => xx
[iMerchantId] => xx
[fSaleAmount] => xx
[fCommissionAmount] => xx
[dClickDate] => xx
[dTransactionDate] => xx
[sClickref] => xx
[aTransactionParts] => Array
(
[0] => stdClass Object
(
[sCommissionGroupName] => STANDARD
[fSaleAmount] => xx
[fCommissionAmount] => xx
[iCommission] => xx
[sCommissionType] => percentage
)
)
)
[1] => stdClass Object
(
[iId] => x
[sStatus] => pending
[sType] => normal
[sIp] => x
[bPaid] =>
[iPaymentId] => x
[iMerchantId] => x
[fSaleAmount] => x
[fCommissionAmount] => x
[dClickDate] => x
[dTransactionDate] => x
[sClickref] => x
[sSearchSiteName] => x
[sSearchSiteKeyword] => x
[aTransactionParts] => Array
(
[0] => stdClass Object
(
[sCommissionGroupName] => DEFAULT
[fSaleAmount] => x
[fCommissionAmount] => x
[iCommission] => x
[sCommissionType] => percentage
)
)
)
)
[getTransactionListCountReturn] => stdClass Object
(
[iRowsReturned] => 2
[iRowsAvailable] => 386
)
)
所以,我的问题是如何在PHP中“解析”这个?我是说如何访问这些数据?我的意思是
$response[0]->sStatus;
感谢您的帮助!
答案 0 :(得分:1)
所有东西都是stdClass
的实例,PHP中的标准类(当然除了数组:))。
这意味着您将使用->
来访问每个对象的属性。
$someSaleAmount =
$response->getTransactionListReturn[0]->aTransactionParts[0]->fSaleAmount;
你可能使用json_decode()
得到了这个。如果您更愿意处理数组而不是对象,则可以将第二个参数设置为true
。
答案 1 :(得分:1)
嗯,第一件事是对象,而不是它的数组,而不是它的对象再次带有一些值。 我会选择这样的东西:
<code>
$response = $obj->getTransactionListReturn();
foreach($response as $key => $value) {
// key is index (0, 1, ..., n)
// value is the variable like iId
echo $value->id;
}
</code>
应该工作。