2013-02-17 2 views
1

나는 페이스 북에서 JSON 응답을 얻었다. $id & $post_id의 값을 검색하는 방법은 무엇입니까?PHP로 JSON 응답을 읽는 법

$response = json_decode (file_get_contents($graph_url)); 
    $id = $response.id; 
    $post_id = $response.post_id;  

     print_r($response); 
     print_r($id); 
     print_r($post_id); 

출력 :

stdClass Object ([id] => 232160686920835 [post_id] => 231794566957447_232160693587501) 

& $post_id $id ... 의 출력 없음 ...

+0

javascript 용으로 PHP를 잘못 사용하고 있습니다.). 그냥'$ id = $ response-> id'를 사용하십시오 – Broncha

답변

4

개체 구문이 잘못되었습니다.

$id = $response->id; 
$post_id = $response->post_id;  

print_r($response); 
print_r($id); 
print_r($post_id); 

을 아니면 배열로 작업하는 것을 선호하는 경우, 당신은 json_decode의 두 번째 인수로 true를 넣을 수 있습니다 : 사용 PHP OOP에서

$response = json_decode (file_get_contents($graph_url), true); 
$id = $response['id']; 
$post_id = $response['post_id'];  

print_r($response); 
print_r($id); 
print_r($post_id); 
+0

고마워요! 나는 이드를 정확하게 잡았다. –

0

-> 사용 대신 . 같다 자바 또는 다른 언어로.