我试图从Flickr中检索一些json,并使用foreach循环显示一些特定数据,就像我用美味和推特一样。 然而,它返回的json格式不同,它似乎没有工作,任何想法家伙?感谢
jsonFlickrFeed({
"title": "Recent Uploads tagged un",
"link": "http://www.flickr.com/photos/tags/un/",
"description": "",
"modified": "2012-02-22T14:48:07Z",
"generator": "http://www.flickr.com/",
"items": [
{
"title": "PLAYA SOLITARIA",
"link": "http://www.flickr.com/photos/lomar_alv/6920550211/",
"media": {"m":"http://farm8.staticflickr.com/7040/6920550211_516eb7ae13_m.jpg"},
"date_taken": "2009-08-25T18:34:25-08:00",
"description":
答案 0 :(得分:1)
您可以传递选项:
$options = array (
'format' => 'json',
'nojsoncallback' => 1
);
答案 1 :(得分:0)
这就是我通常的做法
//Grab the feed
$json_feed = file_get_contents("http://www.WhateverTheFeedUrlIs.com");
//Decode it
$json_to_array = json_decode($json_feed);
//Print it out if you want
echo '<pre>';
print_r($json_to_array);
echo '</pre>';
//Grab specific info
echo $json_to_array->title; //Recent Uploaded Tags
echo $json_to_array->url; //http://www.flickr.com....
echo $json_to_array->items[0]->title; //PLAYA SOLITARIA
答案 2 :(得分:0)
我知道它已经过时了,但对于其他任何想知道这件事的人来说......做:
json_decode(ereg_replace("^jsonFlickrFeed\((.*)\)$", "\\1", stripslashes(strip_tags($STRING_YOU_GOT_BACK_FROM_FLICKR))));
这应该清理响应,以便json_decode()工作。还要注意你可以在那里放一个true来返回一个数组而不是一个带有json_decode()的对象。
实际上,这已被弃用了。你只想用preg_replace()做一个类似的正则表达式。甚至:
$responseString = str_replace(array("\n", "\t"), '', $STRING_BACK_FROM_CURL);
$responseString = stripslashes(strip_tags($responseString));
preg_match('/^jsonFlickrFeed\((.*)\)/i', $responseString, $matches);
$flickrJson = $matches[1];
$flickrObject = json_decode($flickrJson);