Answer the question
In order to leave comments, you need to log in
How to extract city title from json request in PHP script for VK API?
Hello!
I am learning PHP using the VK API as an example. This comes to me:
{
"response": [
{
"id": 3346346,
"first_name": "Имя",
"last_name": "Фамилия",
"sex": 1,
"screen_name": "id43346346",
"bdate": "5.2",
"city": {
"id": 1,
"title": "Москва"
},
"country": {
"id": 1,
"title": "Россия"
},
"photo_max_orig": "https://pp.userapi.com/3453453-O64.jpg?ava=1"
}
]
}
//и извлекаем из ответа его имя
$first_name = $user_info->response[0]->first_name;
//и извлекаем из ответа его фамилию
$last_name = $user_info->response[0]->last_name;
//и извлекаем из ответа его страну
$country = $user_info->response[0]->country;
//и извлекаем из ответа его город
$city = $user_info->response[0]->city;
//С помощью messages.send отправляем ответное сообщение
$request_params = array(
'message' => "Hello, Имя:{$first_name} Фамилия:{$last_name} Страна:{$country} Город:{$city}!",
'user_id' => $user_id,
'access_token' => $token,
'v' => '5.50'
);
$country = $user_info->response[0]->country->title;
$city = $user_info->response[0]->city->title;
Answer the question
In order to leave comments, you need to log in
$country = $user_info->response[0]->country->title;
$city = $user_info->response[0]->city->title;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question