0

我正在尝试使用 Tumblr API,我相信它的 JSON。我正在尝试使用 Php 在下面的 URL 中获取“posts-total”并将其回显。我该怎么做?

http://example.tumblr.com/api/read/json?num=0

谢谢

Update:

我试图使用

$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
$print_r($result); 
echo $result[1]; 

我收到 500 错误。当我试图回显 $result 时,我什么也得不到。

4

2 回答 2

3

我遇到了类似的问题,并认为我解决了。

var tumblr_api_read = {"tumblelog":{"title":"Ex-Sample","description":"A sample document used to provide examples of the various [and <i>varying<\/i>] HTML tags Tumblr puts out. Quote, specifically, has a lot of variants.","name":"example","timezone":"US\/Eastern","cname":false,"feeds":[]},"posts-start":0,"posts-total":"20","posts-type":false,"posts":[]};

看起来被发回的 json 有利于 javascript,而不是纯 json。因此 json_decode 函数在尝试解析它时遇到问题。看来您可以将 debug=1 参数添加到 url 并接收 PHP 可以处理的 json 字符串。

$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0&debug=1'));
$print_r($result); 
echo $result[1];
于 2012-09-27T14:25:51.670 回答
1

简单的php-

$result = json_decode(file_get_contents('http://example.tumblr.com/api/read/json?num=0'));
print_r($result); //will show contents return in an araay format
echo $result[1]; //or whatever the element is
于 2012-05-02T16:06:11.227 回答