2011-11-03 10 views
3

訪問屬性我有以下的已經解碼存儲在$response = $result->response; JSON:PHP在JSON

object(stdClass)#6 (5) { 
    ["EmailAddress"]=> string(18) "[email protected]" 
    ["Name"]=> string(0) "" 
    ["Date"]=> string(19) "2011-10-09 19:32:00" 
    ["State"]=> string(6) "Active" 
    ["CustomFields"]=> array(1) { 
    [0]=>object(stdClass)#7 (2) { 
      ["Key"]=>string(2) "id" 
      ["Value"]=>string(6) "Dl9lIz" 
    } 
    } 

我已經可以訪問與主要屬性(EmailAddress的,名稱等):

$email = $response->{'EmailAddress'}; 
print $email; 

但我需要訪問CustomFields對象中的"Value"部分。我不知道如何深入挖掘。我試圖用PHP來做這件事。

有什麼建議嗎?

回答

4

它包含在數組CustomFields的第一個元素([0])中,因此您可以在數組索引後使用對象運算符(->)訪問它。

print $response->CustomFields[0]->Value;