0

私はTumblrAPIを使おうとしています。その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関数はそれを解析しようとして問題が発生しています。URLにdebug=1引数を追加して、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 に答える