我正在尝试从Flickr中检索一些json,并使用foreach循环来显示一些特定的数据,就像我在delicious和twitter上所做的那样。然而,它返回的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":发布于 2014-11-18 18:53:53
您可以传递选项:
$options = array (
'format' => 'json',
'nojsoncallback' => 1
);发布于 2012-02-23 00:11:47
我通常就是这么做的
//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发布于 2012-10-07 09:06:06
我知道它已经过时了,但对于任何想知道this...do的人来说:
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);https://stackoverflow.com/questions/9398026
复制相似问题