-1

如何在stdclass中使用@登录访问对象我已经在php中使用curl尝试过这个:$response->HotelListResponse->customerSessionId(这有效)但是当我做这样的事情时:$response->HotelListResponse->HotelList->@activePropertyCount返回错误或空字符串

stdClass Object

[HotelListResponse] => stdClass Object
    (
        [customerSessionId] => 0ABAA84E-3DC0-4913-E0C2-5C6541908000
        [numberOfRoomsRequested] => 1
        [moreResultsAvailable] => 1
        [cacheKey] => 6b03dc04:13e0c5c6541:-7ffd
        [cacheLocation] => 10.186.168.78:7302
        [cachedSupplierResponse] => stdClass Object
            (
                [@matchedLocale] => true
                [@matchedCurrency] => true
                [@tpidUsed] => 5001
                [@otherOverheadTime] => 2
                [@candidatePreptime] => 13
                [@supplierResponseTime] => 680
                [@supplierResponseNum] => 25
                [@supplierRequestNum] => 207
                [@cachedTime] => 0
                [@supplierCacheTolerance] => NOT_SUPPORTED
            )

        [HotelList] => stdClass Object
            (
                [@activePropertyCount] => 224
                [@size] => 25
                [HotelSummary] => Array
                    (
                        [0] => stdClass Object
                            (
                                [@ubsScore] => 6144465
                                [@order] => 0
4

1 回答 1

1

您可以通过两种方式做到这一点。

方法一:

使用 Mark Ba​​ker 建议的相同方法调用它,例如使用花括号。花括号用于显式指定变量名的结尾。

$result->HotelListResponse->HotelList->{'@activePropertyCount'};

您可以参考此链接以获取更多信息http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

方法二:

分配@activePropertyCount给某个变量。你可以这样做:

$var = '@activePropertyCount';

然后你可以得到结果:

$result->HotelListResponse->HotelList->$var;

希望这可以帮助你:)

于 2013-04-15T06:53:36.970 回答