Php 从json中提取数据
我只想检索mp4 url(Php 从json中提取数据,php,json,Php,Json,我只想检索mp4 url(http://vid.lsw.example.com/_videos_t4vn23s9jc5498tgj49icfj4678/0000267/_mp4/0267665.mp4?st=BHmB0h98u4JIGsbmnPKrbQ&e=1436437792)从json { "title": "testvideo", "_filename": "testvideo-267665.mp4", "playlist_index": null, "webpage_ur
http://vid.lsw.example.com/_videos_t4vn23s9jc5498tgj49icfj4678/0000267/_mp4/0267665.mp4?st=BHmB0h98u4JIGsbmnPKrbQ&e=1436437792
)从json
{
"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"
}
试试这个
$yt_info = json_decode($yt_json);
echo $yt_info->{'thumbnails'}[0]->{'url'}; //for image
echo $yt_info->url; //for url
yt_info是对象,所以请像上面的语句一样使用。还可以更正json格式以获取url字符串,只需使用
$yt\u info->url
可能是输入错误,但您的json已损坏。是的,json是正确的broken@ikrabbe修正了json…在我复制Paste时弄乱了我修正了我的json+使事情变得清晰…请检查again@user2650277上面的答案适用于你的情况,试试看,这里不起作用。我得到的缩略图是这样的$thumb=$yt_信息['缩略图]代码>不要使用关联数组使用这个json_解码($yt_json)而不是json_解码($yt_json,true),谢谢它的工作,但为什么它不可能通过关联数组。在我的书中,这是一个更干净的方法