从json中提取数据

时间:2015-07-09 10:13:16

标签: php json

我想从json中只检索mp4网址(http://vid.lsw.example.com/_videos_t4vn23s9jc5498tgj49icfj4678/0000267/_mp4/0267665.mp4?st=BHmB0h98u4JIGsbmnPKrbQ&e=1436437792)。

{
  "title": "testvideo",
  "_filename": "testvideo-267665.mp4",
  "playlist_index": null,
  "webpage_url_basename": "267665",
  "http_headers": {
    "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/20.0 (Chrome)",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "en-us,en;q=0.5"
  },
  "requested_subtitles": null,
  "format": "0 - unknown",
  "webpage_url": "http://www.example.com/267665",
  "playlist": null,
  "ext": "mp4",
  "extractor": "testExtract",
  "thumbnails": [
    {
      "id": "0",
      "url": "http://img.l3.cdn.example.com/_thumbs/0000267/0267665/0267665_002m.jpg"
    }
  ],
  "format_id": "0",
  "id": "267665",
  "url": "http://vid.lsw.example.com/_videos_t4vn23s9jc5498tgj49icfj4678/0000267/_mp4/0267665.mp4?st=BHmB0h98u4JIGsbmnPKrbQ&e=1436437792",
  "extractor_key": "TestExtract",
  "fulltitle": "TestVideo",
  "display_id": "267665",
  "thumbnail": "http://img.example.com/_thumbs/0000267/0267665/0267665_002m.jpg"
}

2 个答案:

答案 0 :(得分:2)

试试这个

$yt_info = json_decode($yt_json);

echo $yt_info->{'thumbnails'}[0]->{'url'}; //for image
echo $yt_info->url; //for url

yt_info是对象,所以像上面的语句一样使用。并纠正你的json格式

答案 1 :(得分:0)

要获取网址字符串,只需使用

即可

$yt_info->url