【发布时间】:2011-09-27 13:14:14
【问题描述】:
我在从 Json 数组中检索值时遇到了困难。我有一个使用 json_encode 创建的 Json 数据集。这是使用 json_decode 并使用 print_r 显示后的样子:
Array ( [0] => stdClass Object ( [postID] => 1961 [postTitle] => Kiss My Fairy [previewThumb] => 2011/09/Kiss-My-Fairy-Ibiza-essentialibiza-2011_feature.jpg [blogContent] => Ibiza has always had a flair for the extravagant, inhibitions are checked in at the airport when the floods of tourists arrive and the locals have embraced a freedom of partying that has turned the quiet Mediterranean island into the Mecca... ) ) a_post_data_array = 1
实现这一点的代码如下:
$post_data_URL = "http://myurl.com/news/scrape/facebook-like-chart-ID.php?post_name=kiss-my-fairy";
$post_data_response = file_get_contents($post_data_URL);
$a_post_data_array=json_decode($post_data_response);
我现在只需要从这个数组中检索一些值来用作变量。该数组将永远只有一组值。我正在使用以下代码,但它不起作用。
echo "**** -- " . $a_post_data_array[post_title] . "<br>";
有人可以帮忙吗?对不起,这太基本了。我一直在网上搜索,但找不到任何这样的例子。
【问题讨论】: