我正在解析從YouTube返回的JSON數組,並在創建一個新數組時使用它返回的條目內容。然後我把這個數組放到foreach
循環中,並嘗試訪問我需要的信息。當我這樣做echo $d->title->type
輸出text
(這是它的價值),但是當我試圖獲得視頻$d->title->$t
的標題不起作用。以下是我正在使用的輸出。我需要從這個數組中獲取的兩條信息是前面提到的,這是視頻的標題,$d->media$group->media$content->url
是用於在iPhone上部署的網址。爲什麼無法訪問我從YouTube返回的JSON數組元素?
[{"id":{"$t":"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/jPF1JA6n054"},"published":{"$t":"2010-09-21T17:36:05.000Z"},"updated":{"$t":"2011-08-18T16:43:57.000Z"},"category":[{"scheme":"http:\/\/schemas.google.com\/g\/2005#kind","term":"http:\/\/gdata.youtube.com\/schemas\/2007#video"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/categories.cat","term":"Music","label":"Music"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Back"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Pocket"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Memory"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Back Pocket Memory"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"guitar"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"vocals"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Awesome"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"drums"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"bass"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"amazing band"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"amazing guitar"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"fun"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"funny"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"cats"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"cute puppies"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"Obama"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"star wars"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"gaga"},{"scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/keywords.cat","term":"sexy"}],"title":{"$t":"Back Pocket Memory : 'Bergerac' Official Music Video","type":"text"},"content":{"$t":"Our official music video for the single from our album, 'Strangers'. Made by our amazing friends at 18mm Productions. Check them out at: www.18mmproductions.com. youtube.com\/18mmproductions, and Twitter: @18mmproductions. Enjoy the video, we are proud to see all of your lovely faces in it!","type":"text"},"link":[{"rel":"alternate","type":"text\/html","href":"http:\/\/www.youtube.com\/watch?v=jPF1JA6n054&feature=youtube_gdata"},{"rel":"http:\/\/gdata.youtube.com\/schemas\/2007#video.responses","type":"application\/atom+xml","href":"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/jPF1JA6n054\/responses"},{"rel":"http:\/\/gdata.youtube.com\/schemas\/2007#video.related","type":"application\/atom+xml","href":"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/jPF1JA6n054\/related"},{"rel":"http:\/\/gdata.youtube.com\/schemas\/2007#mobile","type":"text\/html","href":"http:\/\/m.youtube.com\/details?v=jPF1JA6n054"},{"rel":"self","type":"application\/atom+xml","href":"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/jPF1JA6n054"}],"author":[{"name":{"$t":"BackPocketMemory"},"uri":{"$t":"http:\/\/gdata.youtube.com\/feeds\/api\/users\/backpocketmemory"}}],"gd$comments":{"gd$feedLink":{"href":"http:\/\/gdata.youtube.com\/feeds\/api\/videos\/jPF1JA6n054\/comments","countHint":19}},"media$group":{"media$category":[{"$t":"Music","label":"Music","scheme":"http:\/\/gdata.youtube.com\/schemas\/2007\/categories.cat"}],"media$content":[{"url":"http:\/\/www.youtube.com\/v\/jPF1JA6n054?f=videos&app=youtube_gdata","type":"application\/x-shockwave-flash","medium":"video","isDefault":"true","expression":"full","duration":244,"yt$format":5},{"url":"rtsp:\/\/v8.cache3.c.youtube.com\/CiILENy73wIaGQme06cOJHXxjBMYDSANFEgGUgZ2aWRlb3MM\/0\/0\/0\/video.3gp","type":"video\/3gpp","medium":"video","expression":"full","duration":244,"yt$format":1},{"url":"rtsp:\/\/v7.cache5.c.youtube.com\/CiILENy73wIaGQme06cOJHXxjBMYESARFEgGUgZ2aWRlb3MM\/0\/0\/0\/video.3gp","type":"video\/3gpp","medium":"video","expression":"full","duration":244,"yt$format":6}],"media$description":{"$t":"Our official music video for the single from our album, 'Strangers'. Made by our amazing friends at 18mm Productions. Check them out at: www.18mmproductions.com. youtube.com\/18mmproductions, and Twitter: @18mmproductions. Enjoy the video, we are proud to see all of your lovely faces in it!","type":"plain"},"media$keywords":{"$t":"Back, Pocket, Memory, Back Pocket Memory, guitar, vocals, Awesome, drums, bass, amazing band, amazing guitar, fun, funny, cats, cute puppies, Obama, star wars, gaga, sexy"},"media$player":[{"url":"http:\/\/www.youtube.com\/watch?v=jPF1JA6n054&feature=youtube_gdata_player"}],"media$thumbnail":[{"url":"http:\/\/i.ytimg.com\/vi\/jPF1JA6n054\/0.jpg","height":360,"width":480,"time":"00:02:02"},{"url":"http:\/\/i.ytimg.com\/vi\/jPF1JA6n054\/1.jpg","height":90,"width":120,"time":"00:01:01"},{"url":"http:\/\/i.ytimg.com\/vi\/jPF1JA6n054\/2.jpg","height":90,"width":120,"time":"00:02:02"},{"url":"http:\/\/i.ytimg.com\/vi\/jPF1JA6n054\/3.jpg","height":90,"width":120,"time":"00:03:03"}],"media$title":{"$t":"Back Pocket Memory : 'Bergerac' Official Music Video","type":"plain"},"yt$duration":{"seconds":"244"}},"gd$rating":{"average":4.9322033,"max":5,"min":1,"numRaters":59,"rel":"http:\/\/schemas.google.com\/g\/2005#overall"},"yt$statistics":{"favoriteCount":"42","viewCount":"4813"}}]}
可能的[使用美元符號作爲節點名稱訪問PHP對象]的副本(http://stackoverflow.com/questions/4378807/access-a-php-object-with-dollar-sign-as-node-name) – mario