1

我收到了来自 Facebook 的 JSON 响应。如何检索$id&的值$post_id

    $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 )

没有输出$id& $post_id ... ...

4

2 回答 2

4

您的对象语法错误。利用:

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

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

或者,如果您更喜欢使用数组,您可以将true其作为 json_decode 的第二个参数:

$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 );
于 2013-02-17T17:42:10.833 回答
0

在 PHP OOP 中

->.在 Java 或其他语言中使用而不是like。

于 2013-02-17T17:45:10.020 回答