如何在php中访问此变量?
result-> message-> from-> id
我用json_decode()解码了返回的json 我想通过上述方法获得价值
{
"ok": true,
"result": [
{
"update_id": 176446579,
"message": {
"message_id": 7,
"from": {
"id": 468822221,
"is_bot": false,
"first_name": "M.GH",
"last_name": "2003",
"username": "moji_2003",
"language_code": "fa"
},
"chat": {
"id": 468822221,
"first_name": "M.GH",
"last_name": "2003",
"username": "moji_2003",
"type": "private"
},
"date": 1550384619,
"text": "salam"
}
}
]
}
答案 0 :(得分:1)
$result
是一个数组,因此您需要先访问该数组中的第一个元素:
$json = json_decode('JSON_STRING');
$id = $json->result[0]->message->form->id;
答案 1 :(得分:1)
是的,您可以通过以下方式访问它:
$data = json_decode($yourJsonString);
echo $data->result[0]->message->from->id;