简体   繁体   中英

How to decode Json response from facebook

I have decoded the JSON response fron facebook using $my_friends = json_decode(file_get_contents($frens)); and print_r($my_friends); gives the following response :

    stdClass Object
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [name] => Mrinal Kumar Rai Baruah
                    [id] => 546111977
                )

            [1] => stdClass Object
                (
                    [name] => Roshan Khangembam
                    [id] => 553139665
                )

            [2] => stdClass Object
                (
                    [name] => Tarunesh Kumar Saurav
                    [id] => 620690126
                )
.........................
        )

)

I am new to JSON and m very confused . How can I iterate the above response to get the name ?

foreach($my_friends['data'] as $key => $val) {
   echo "Friend #{$key} = {$val['name']}\n";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM