如何解析网址响应?

时间:2015-08-10 09:35:38

标签: php parsing curl response

我得到了这样的网址回复。我想要sid的价值。我怎么能得到这个?

{"response": "success","body":{ "sid" : "5f255c86a", "role" : "user" }}

2 个答案:

答案 0 :(得分:2)

它是JSON格式,因此请使用json_decode()函数。

$response = json_decode($response);

echo $response->body->sid;

$response = json_decode($response, true);
echo $response['body']['sid'];

如果将第二个参数传递为true,则它将返回关联数组。

答案 1 :(得分:1)

以上回复查看b JSON,因此您可以使用json_decode()函数。

尝试

$response = file_get_contents($url);
$json = json_decode($response);

echo $json->body->sid;

注意您需要将$url替换为响应页面的网址。

相关问题