解析affiliateservice api响应

发布于 2025-01-04 12:13:59 字数 2925 浏览 0 评论 0原文

我通过 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; 

谢谢你的帮助!

I am fetching the TransactionList through affiliateservice api.
My print_r($response) gives me this (I had to put xx but actually there are numbers there):

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
        )

)

So, my question is how can I "parse" this in PHP? I mean how can I access these data? I mean something like

$response[0]->sStatus; 

Thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少跟Wǒ拽 2025-01-11 12:13:59

一切都是 stdClass 的实例,这是 PHP 中的标准类(当然,数组除外:))。

这意味着您将使用 -> 来访问每个对象的属性。

$someSaleAmount = 
       $response->getTransactionListReturn[0]->aTransactionParts[0]->fSaleAmount;

您可能是通过使用 json_decode() 得到的。如果您更愿意处理数组而不是对象,可以将第二个参数设置为 true

Everything is an instance of the stdClass, the standard class in PHP (except for the arrays, of course :)).

This means you would use -> to access the properties of each object.

$someSaleAmount = 
       $response->getTransactionListReturn[0]->aTransactionParts[0]->fSaleAmount;

You probably got this from using json_decode(). You can set the second parameter to true if you'd rather deal with arrays than objects.

ˉ厌 2025-01-11 12:13:59

好吧,首先是对象,然后是数组,然后又是带有一些值的对象。
我会选择这样的东西:

<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>

应该有效。

Well, the first thing is object, than it's array, than it's object again with some values.
I would go for something like this:

<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>

Should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文