2012-03-16 78 views
1

我想解析一個twitter用戶stats(用php) - 我很不熟悉解析json,所以這給我一點頭痛(我在這裏錯過了一些愚蠢的東西知道)。我已經看過一堆來自其他人的答案/帖子,但不能完全盯住它。任何幫助表示讚賞。用json解析twitter狀態php

本質上我想得到的是[url]和[文本],但我不斷收到錯誤在PHP中。

[0] => stdClass Object 
    (
     [in_reply_to_user_id] => 
     [in_reply_to_status_id_str] => 
     [retweet_count] => 0 
     [id_str] => 180735710897250304 
     [in_reply_to_user_id_str] => 
     [geo] => 
     [favorited] => 
     [user] => stdClass Object 
      (
       [id_str] => 46023 
       [id] => 460 
      ) 

     [in_reply_to_status_id] => 
     [in_reply_to_screen_name] => 
     [truncated] => 
     [contributors] => 
     [source] => Facebook 
     [entities] => stdClass Object 
      (
       [hashtags] => Array 
        (
        ) 

       [urls] => Array 
        (
         [0] => stdClass Object 
          (
           [expanded_url] => http://www.buzzfeed.co 
           [url] => http://t.c 
           [indices] => Array 
            (
             [0] => 0 
             [1] => 20 
            ) 

           [display_url] => buzzfeed.com/c 
          ) 

         [1] => stdClass Object 
          (
           [expanded_url] => http://fb 
           [url] => http://t. 
           [indices] => Array 
            (
             [0] => 21 
             [1] => 41 
            ) 

           [display_url] => fb.m 
          ) 

        ) 

       [user_mentions] => Array 
        (
        ) 

      ) 

     [coordinates] => 
     [retweeted] => 
     [id] => 180735 
     [created_at] => Fri Mar 16 19:22:06 +0000 2012 
     [possibly_sensitive] => 
     [place] => 
     [text] => http://t.co 
+0

請問您可以發佈您使用的代碼來獲取此輸出嗎? – Fitz 2012-03-16 20:52:00

回答

1

json_decode函數有一個可選的第二參數來代替返回對象的關聯數組。

嘗試: json_decode($your_json_var, false)

然後,你可以檢索值正常,你會與任何數組。

+0

Yup知道這一點,但試圖繞過它出於某種原因。 – 2012-03-16 22:00:20

0

您還可以得到價值如下例如:

echo $tweets[0]->id_str; 

這將顯示您的JSON數據的ID_STR值。