2011-11-17 112 views
-1

我有一個php代碼,調用facebook api me/home並獲取此結果。但問題是不知道如何解碼。所以我想在這裏尋求幫助。指導我解碼這個對象嗎?

[1]=> 
object(stdClass)#276 (9) { 
["id"]=> 
string(31) "100000000155611_312548192088517" 
["from"]=> 
object(stdClass)#275 (2) { 
    ["name"]=> 
    string(13) "Jun Revistual" 
    ["id"]=> 
    string(15) "100000000155611" 
} 
["message"]=> 
string(95) "lifes interesting... if you stay alive, good things are bound to happen. :)) 
One Piece Movie 4" 
["actions"]=> 
array(2) { 
    [0]=> 
    object(stdClass)#274 (2) { 
    ["name"]=> 
    string(7) "Comment" 
    ["link"]=> 
    string(61) "http://www.facebook.com/100000000155611/posts/312548192088517" 
    } 
    [1]=> 
    object(stdClass)#273 (2) { 
    ["name"]=> 
    string(4) "Like" 
    ["link"]=> 
    string(61) "http://www.facebook.com/100000000155611/posts/312548192088517" 
    } 
} 
["type"]=> 
string(6) "status" 
["created_time"]=> 
string(24) "2011-11-17T05:18:17+0000" 
["updated_time"]=> 
string(24) "2011-11-17T05:19:31+0000" 
["likes"]=> 
object(stdClass)#272 (2) { 
    ["data"]=> 
    array(1) { 
    [0]=> 
    object(stdClass)#271 (2) { 
     ["name"]=> 
     string(16) "Andrei Natividad" 
     ["id"]=> 
     string(9) "614714754" 
    } 
    } 
    ["count"]=> 
    int(1) 
} 
["comments"]=> 
object(stdClass)#269 (2) { 
    ["data"]=> 
    array(2) { 
    [0]=> 
    object(stdClass)#258 (4) { 
     ["id"]=> 
     string(39) "100000000155611_312548192088517_4977358" 
     ["from"]=> 
     object(stdClass)#267 (2) { 
     ["name"]=> 
     string(16) "Andrei Natividad" 
     ["id"]=> 
     string(9) "614714754" 
     } 
     ["message"]=> 
     string(17) "what's the title?" 
     ["created_time"]=> 
     string(24) "2011-11-17T05:18:45+0000" 
    } 
    [1]=> 
    object(stdClass)#260 (5) { 
     ["id"]=> 
     string(39) "100000000155611_312548192088517_4977363" 
     ["from"]=> 
     object(stdClass)#266 (2) { 
     ["name"]=> 
     string(13) "Jun Revistual" 
     ["id"]=> 
     string(15) "100000000155611" 
     } 
     ["message"]=> 
     string(37) "One Piece Movie 4: Dead End Adventure" 
     ["created_time"]=> 
     string(24) "2011-11-17T05:19:31+0000" 
     ["likes"]=> 
     int(1) 
    } 
    } 
    ["count"]=> 
    int(2) 
} 
} 

到現在我還只是在這裏:

foreach($wall as $value) { 
echo "<pre>"; 
echo $value[0]->id; 
print_r($value); 
echo "</pre>"; 
} 

甚至不知道這是否是正確的。

+1

這看起來像它已經解碼......你指的是解碼? –

+0

我相信你已經做對了,數據已經從json解碼出來了,你正在以正確的方式訪問它。 – Arfeen

+0

我編輯了我的示例以獲得更多的說明。我想要的是獲得Jun Revistual的海報名稱和他的消息,即「生活有趣......如果你......」。那些人在他的帖子中評論道。我想在我的臉書主頁中構造它。 –

回答

0

嘗試使用此代碼:

$data = $facebook_object_response; 

    echo $data->data[0]->id; 

,如果它是一個對象,你可以通過訪問數據「 - >」如果是數組訪問它像這樣「[<index>]」。

+0

完成了工作,並添加了一個for循環,然後它顯示了一個結果,但在最後一部分,這引發了一個錯誤:致命錯誤:不能使用stdClass類型的對象作爲數組在/my_app.php上行59 –

+0

嘗試添加if循環中的if條件來確定它是否仍在訪問對象 –