[英]How to read the JSON response by php
我从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
......
您的对象语法错误。 采用:
$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 );
在PHP OOP中
->
用来代替.
比如Java或其他语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.