显示URL中的json内容

时间:2017-02-09 09:18:18

标签: php json

从以下网址:http://www.test.com/question,我得到以下结果:

{{1}}

问题:如何在 id2 字段中显示网址内容。

1 个答案:

答案 0 :(得分:1)

$json = '{
"status": "success",
"id": "https://api.test.com/me",
"denormalized": {
    "https://api.test.com/me": {
        "data": {
            "user": {
               "id2": "https://api.test.com/users/20"
            },
            "sauce": "sadasdksdls",
            "session_id": "opoqwrpoqirpoewripwor"
        },
        "relations": {
            "profile": "https://api.test.com/users/20",
            "quick_chat_profile": "https://api.test.com/profile/20"
        },
        "updates": null
    }
}
}';

$array = json_decode($json, true);

$id2_data = file_get_contents($a['denormalized']['https://api.test.com/me']['data']['user']['id2']);

步骤1:将返回的json分配给变量$ json 第2步:将json转换为php数组
第3步:将id2作为$ a [&#39;非规范化&#39;] [&#39;数据&#39;] [&#39;用户&#39;] [&#39; id2&#39;] < / p>