2012-03-16 1 views
1

트위터 사용자 통계 (PHP 사용)를 구문 분석하려고합니다. json을 파싱하는 것에 익숙하지 않아서 제게 약간의 두통이 생깁니다. 알고있다). 나는 많은 사람들의 답변/게시물을 보았지만 꽤 못 견딜 수는 없다. 어떤 도움을 주셔서 감사합니다.json php로 구문 분석 twitter status

필자가 원하는 것은 [url]과 [text]이지만 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

답변

1

json_decode 함수는 객체 대신 결합 배열을 반환 선택적 번째 파라미터 걸린다.

보십시오 : 당신이 어떤 배열와 마찬가지로 json_decode($your_json_var, false)

그런 다음, 당신은 일반적으로 값을 검색 할 수 있습니다.

+0

Yup은 이것을 알고 있었지만 한 가지 이유 또는 다른 이유로 그것을 둘러 오려고했습니다. –

0

또한 예를 들어 아래와 같은 값을 얻을 수 있습니다 :

echo $tweets[0]->id_str; 

이것은 당신의 JSON 데이터로부터 ID_STR 값을 표시합니다.