如何获取json对象值

时间:2014-06-13 05:34:14

标签: php json

我有json返回对象值是这样的:

{
"statuses": [
    {
        "metadata": {
            "result_type": "recent",
            "iso_language_code": "en"
        },
        "created_at": "Sun Jun 08 20:46:44 +0000 2014",
        "id": 475740733211947008,
        "id_str": "475740733211947008",
        "text": "RT @XMenMovies: #JenniferLawrence brings the many shapes of #Mystique to life in #XMen: Days of Future Past. http:\/\/t.co\/cIpp5lGdDH http:\/\/\u2026",
        "source": "Twitter for Mac<\/a>",
        "truncated": false,
        "in_reply_to_status_id": null,
        "in_reply_to_status_id_str": null,
        "in_reply_to_user_id": null,
        "in_reply_to_user_id_str": null,
        "in_reply_to_screen_name": null
    }
]

}

我正在使用数组中的值,如下所示:data.statuses,我有另一个json返回值,如下所示:

{
"0": [
    {
        "metadata": {
            "result_type": "recent",
            "iso_language_code": "en"
        },
        "created_at": "Sun Jun 08 20:46:44 +0000 2014",
        "id": 475740733211947000,
        "id_str": "475740733211947008",
        "text": "RT @XMenMovies: #JenniferLawrence brings the many shapes of #Mystique to life in #XMen: Days of Future Past. http://t.co/cIpp5lGdDH http://…",
        "source": "Twitter for Mac</a>",
        "truncated": false,
        "in_reply_to_status_id": null,
        "in_reply_to_status_id_str": null,
        "in_reply_to_user_id": null,
        "in_reply_to_user_id_str": null,
        "in_reply_to_screen_name": null
    }
]

}

我有'0'而不是任何名字。如何获得这个价值?

1 个答案:

答案 0 :(得分:0)

尝试以下方法:)谢谢以后!

$jsonData = '{ "user":"John", "age":22, "country":"United States" }';
$phpArray = json_decode($jsonData);
print_r($phpArray);
foreach ($phpArray as $key => $value) { 
    echo "<p>$key | $value</p>";
}