在php中访问此STDCLASS对象
如何使用@sign-in stdclass访问对象我已经用curl在php中尝试过了: $response->hotellisterresponse->customerSessionId(这很管用),但当我这样做时: $response->hotellistsresponse->HotelList->@activePropertyCount返回错误或空字符串在php中访问此STDCLASS对象,php,arrays,oop,curl,stdclass,Php,Arrays,Oop,Curl,Stdclass,如何使用@sign-in stdclass访问对象我已经用curl在php中尝试过了: $response->hotellisterresponse->customerSessionId(这很管用),但当我这样做时: $response->hotellistsresponse->HotelList->@activePropertyCount返回错误或空字符串 stdClass Object [HotelListResponse] => stdClass Object (
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
你可以用两种方法来做 方法1: 使用马克·贝克建议的方法调用它,比如使用大括号。大括号用于显式指定变量名的结尾
$result->HotelListResponse->HotelList->{'@activePropertyCount'};
您可以参考此链接了解更多信息
方法2:
将@activePropertyCount
分配给某个变量。你可以这样做:
$var = '@activePropertyCount';
然后,您可以通过以下方式获得结果:
$result->HotelListResponse->HotelList->$var;
希望这对您有所帮助:)
$response->HotelList->HotelList->{@activePropertyCount}