本文介绍了使用PHP读取Json数据响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用php读取JSON数据响应?响应t来自第三方的用户身份验证之后.首先,我只想要displayName
和preferredUsername
数据.
How can I read a JSON data response using php? The response t comes after user authentication done from a third party. Primarily, I just want displayName
and preferredUsername
data.
Json回复:
{
"stat": "ok",
"profile": {
"providerName": "testing",
"identifier": "http://testing.com/58263223",
"displayName": "testing",
"preferredUsername": "testing",
"name": {
"formatted": "testing"
},
"url": "http://testing.com/testing/",
"photo": "https://securecdn.testing.com/uploads/users/5826/3223/avatar32.jpg?1373393837",
"providerSpecifier": "testing"
}
}
推荐答案
您可以使用json_decode
( http://php.net/manual/en/function.json-decode.php )函数对结果进行解码,然后检索值:
You can use the json_decode
(http://php.net/manual/en/function.json-decode.php) function to decode your result then retrieve the value:
$json_data = '{
"stat": "ok",
"profile": {
"providerName": "testing",
"identifier": "http://testing.com/58263223",
"displayName": "testing",
"preferredUsername": "testing",
"name": {
"formatted": "testing"
},
"url": "http://testing.com/testing/",
"photo": "https://securecdn.testing.com/uploads/users/5826/3223/avatar32.jpg?1373393837",
"providerSpecifier": "testing"
}
}';
$json = json_decode($json_data);
echo $json->profile->displayName;
echo $json->profile->preferredUsername;
这篇关于使用PHP读取Json数据响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!