开发者

Accessing data from a json structure

I am loading in a JSON feed from Facebook (snippet below).

{
   "data": [
      {
         "id": "115972604762",
         "from": {
            "name": "Title Here",
            "category": "Musicians",
            "id": "20274769762"
         },
         "name": "It was an amazing gig!!",
         "picture": "http://photos-h.ak.fbcdn.net/hphotos-ak-snc1/hs196.snc1/6616_115972604762_20274769762_2185148_6347071_s.jpg",
         "source": "http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs196.snc1/6616_11597开发者_Go百科2604762_20274769762_2185148_6347071_n.jpg",
         "height": 453,
         "width": 604,
         "images": [
            {

I am loading it in using $data['pics'] = json_decode(file_get_contents('https://graph.facebook.com/'. $id .'/photos'));

How would I go about echo'ing out the from->name value to get the 'Title Here' value?


I think it should just be this:

$array = json_decode(file_get_contents('https://graph.facebook.com/'. $id .'/photos'));
echo $array["data"]["from"]["name"];

You can echo out the array using print_r($array) and then see the structure of your php array if it didn't work as expected.


First thing I would do is var_dump() the response, that would explain the exact structure of how PHP has decoded it. My guess is that $response['data']['from']['name'] might work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜