嘗試從媒體中拾取第一個網址->
返回的JSON中的媒體元數據。收到此錯誤:意外' - >'(T_OBJECT_OPERATOR),期待','或';'
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';'
我的代碼:
foreach ($articles->results as $article){
echo "<div class='story'>
<div class='photo'>";
echo "<img src='" . $article->media->media-metadata->url[0] . "' />";
echo "<h3>" . $article->title . "</h3>";
echo "<p>" . $article->abstract . "</p>";
echo "<hr />";
echo "</div></div>";
}
例JSON:
object(stdClass)#20 (18) {
["url"]=> string(82) "http://www.nytimes.com/2013/08/20/health/a-dry-pipeline-for-psychiatric-drugs.html"
["adx_keywords"]=> string(91) "Drugs (Pharmaceuticals);Depression (Mental);Mental Health and Disorders;Medicine and Health"
["column"]=> string(4) "Mind"
["section"]=> string(6) "Health"
["byline"]=> string(28) "By RICHARD A. FRIEDMAN, M.D."
["type"]=> string(7) "Article"
["title"]=> string(36) "A Dry Pipeline for Psychiatric Drugs"
["abstract"]=> string(122) "With rare exceptions, it is hard to think of a single truly novel psychotropic drug that has emerged in the last 30 years."
["published_date"]=> string(10) "2013-08-20"
["source"]=> string(18) "The New York Times"
["id"]=> string(15) "100000002395456"
["asset_id"]=> float(1.00000002395E+14)
["views"]=> int(2)
["des_facet"]=> array(4) {
[0]=> string(23) "DRUGS (PHARMACEUTICALS)"
[1]=> string(19) "DEPRESSION (MENTAL)" [2]=> string(27) "MENTAL HEALTH AND DISORDERS"
[3]=> string(19) "MEDICINE AND HEALTH" }
["org_facet"]=> string(0) ""
["per_facet"]=> string(0) ""
["geo_facet"]=> string(0) ""
["media"]=> array(1) {
[0]=> object(stdClass)#21 (5) {
["type"]=> string(5) "image"
["subtype"]=> string(5) "photo"
["caption"]=> string(0) ""
["copyright"]=> string(12) "Yarek Waszul"
["media-metadata"]=> array(7) {
[0]=> object(stdClass)#22 (4) {
["url"]=> string(91) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-thumbStandard.jpg"
["format"]=> string(18) "Standard Thumbnail"
["height"]=> int(75)
["width"]=> int(75) }
[1]=> object(stdClass)#23 (4) {
["url"]=> string(91) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-articleInline.jpg"
["format"]=> string(6) "Normal"
["height"]=> int(127)
["width"]=> int(190) }
[2]=> object(stdClass)#24 (4) {
["url"]=> string(88) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-superJumbo.jpg"
["format"]=> string(10) "superJumbo"
["height"]=> int(1080)
["width"]=> int(1620) }
[3]=> object(stdClass)#25 (4) {
["url"]=> string(87) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-square640.jpg"
["format"]=> string(9) "square640"
["height"]=> int(640)
["width"]=> int(640) }
[4]=> object(stdClass)#26 (4) {
["url"]=> string(84) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-sfSpan.jpg"
["format"]=> string(5) "Large"
["height"]=> int(263)
["width"]=> int(395) }
[5]=> object(stdClass)#27 (4) {
["url"]=> string(87) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-square320.jpg"
["format"]=> string(9) "square320"
["height"]=> int(320)
["width"]=> int(320) }
[6]=> object(stdClass)#28 (4) {
["url"]=> string(88) "http://graphics8.nytimes.com/images/2013/08/20/science/20MIND_SPAN/20MIND-thumbLarge.jpg"
["format"]=> string(10) "thumbLarge"
["height"]=> int(150)
["width"]=> int(150)
}
}
}
}
}
讓我知道如果你需要更多的細節。
是,這是由於工作! – user2673468