문제

How to access objects with @ sign in stdclass i have tried this in php with curl: $response->HotelListResponse->customerSessionId (this works) but when i do something like this: $response->HotelListResponse->HotelList->@activePropertyCount return error or null string

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
도움이 되었습니까?

해결책

You can do this in two ways.

Method 1:

Call it using the same method that Mark Baker Suggested like using curly braces. Curly braces are used to explicitly specify the end of a variable name.

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

You can refer this link for more info http://php.net/manual/en/language.types.string.php#language.types.string.parsing.complex

Method 2:

Assign @activePropertyCount to some variable. You can do like :

$var = '@activePropertyCount';

Then you can get the result from :

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

Hope this helps you :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top