当我试图找出美味书签的总数时,美味书签返回了一个json文件,当解码时它是:
Array (
[0] => stdClass Object (
[hash] => e60558db2d649c8a1933d50f9e5b199a
[title] => ISRAEL: Thousands march in Jerusalem rally, Israel still kicking
new families out of land they've owned for 60+ years
[url] => http://english.aljazeera.net/news/middleeast/2010/03/2010362141312196.html
[total_posts] => 2
[top_tags] => Array ()
)
)该数组是一个stdClass对象。如何使用PHP提取total_count。
由于我不知道如何提取它,所以我使用strpos来查找'total_count‘,然后我从该位置剪切字符串,然后从中提取整数。:) BUt它太长了。
已解决
发布于 2010-03-10 21:20:50
如果您在json_decode中传递第二个参数true,它将返回一个常规数组,而不是对象。您可能会发现这更容易使用。
$array = json_decode($json, true);
发布于 2010-07-09 18:19:52
如果您在json_decode中传递第二个参数true,它将返回一个常规数组,而不是对象。您可能会发现这更容易使用。
$array = json_decode($json, true);发布于 2010-03-10 21:09:01
你试过了吗?
echo $stdClass->total_posts;https://stackoverflow.com/questions/2417011
复制相似问题