2013-04-15 74 views
-1

如何在stdclass中使用@符号访问对象我曾尝试在PHP中使用curl: $ response-> HotelListResponse-> customerSessionId(这有效)但是当我做这样的事情时: $响应 - > HotelListResponse-> HotelList - > @ activePropertyCount返回错误或空字符串访问此STDCLASS对象在PHP

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

'$响应 - > HotelListResponse-> HotelList - > {'@ activePropertyCount'}' –

回答

1

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

方法1:

使用马克·贝克建议喜欢用花括号同样的方法调用它。大括号用于明确指定变量名称的结尾。

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

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

方法2:

分配@activePropertyCount一些变量。你可以这样做:

$var = '@activePropertyCount'; 

然后你就可以得到结果来自:

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

希望这有助于你:)

+0

thankyou it works –