Answer the question
In order to leave comments, you need to log in
Can't get data from JSON, what should I do?
Good night, well, or evening. Maybe the question is stupid, but I've been suffering for 2 hours already.
I'm getting JSON from the vk api server and I'm trying to get data from it.
Everything used to work for me, but something happened and everything stopped working.
Here's the script that worked:
$json_users = $vk->request('messages.getConversationMembers', ['peer_id' => $peer_id]);
foreach ($json_users as $profile) {
$request .= "(".$profile['profiles']['id'].", $chat_id),";
}
$request = mb_substr($request, 0, -1);
$db->query($request);
$admin_id = $json_users->items[0]->member_id;
$vk->sendMessage($peer_id, json_encode($json_users));
$vk->sendMessage($peer_id, "creator id: $admin_id");
{"items":[{"member_id":420026899,"invited_by":420026899,"join_date":1578569731,"is_admin":true,"is_owner":true},{"member_id":547543178,"invited_by":420026899,"join_date":1578569731},{"member_id":-190687635,"invited_by":420026899,"join_date":1578574330,"is_admin":true},{"member_id":404149344,"invited_by":420026899,"join_date":1578583011},{"member_id":406136075,"invited_by":420026899,"join_date":1578769214},{"member_id":544097332,"invited_by":420026899,"join_date":1578817796}],"count":6,"profiles":[{"id":404149344,"first_name":"German","last_name":"Rudenko","sex":2,"screen_name":"yip.su2z9qe5","photo_50":"https:\/\/sun1-84.userapi.com\/c855520\/v855520688\/1bb4a9\/UKDJdSZUJEo.jpg?ava=1","photo_100":"https:\/\/sun1-95.userapi.com\/c855520\/v855520688\/1bb4a8\/K1iTkyCWqOQ.jpg?ava=1","online":0,"online_info":{"visible":true,"last_seen":1578855094,"app_id":2274003,"is_mobile":true}},{"id":406136075,"first_name":"\u0410\u0440\u0442\u0435\u043c","last_name":"\u041a\u0438\u0441\u0435\u043b\u0435\u0432","sex":2,"screen_name":"b0ga401","photo_50":"https:\/\/sun1-19.userapi.com\/c206520\/v206520130\/1c93a\/tFZPNLrFrD0.jpg?ava=1","photo_100":"https:\/\/sun1-22.userapi.com\/c206520\/v206520130\/1c939\/rVN8sVjwxU8.jpg?ava=1","online":0,"online_info":{"visible":false,"status":"recently"}},{"id":420026899,"first_name":"\u041c\u0430\u043a\u0441\u0438\u043c","last_name":"\u041f\u043b\u043e\u0442\u043d\u0438\u043a\u043e\u0432","sex":2,"screen_name":"iotkroutebejisn","photo_50":"https:\/\/sun1-87.userapi.com\/c857328\/v857328056\/9d3b0\/iqOo7GGnTrI.jpg?ava=1","photo_100":"https:\/\/sun1-26.userapi.com\/c857328\/v857328056\/9d3af\/oHXDFQ1Kcig.jpg?ava=1","online":1,"online_info":{"visible":true,"is_online":true}},{"id":544097332,"first_name":"\u0421\u043e\u043d\u044f","last_name":"\u041d\u0430\u0441\u0442\u044e\u0448\u043a\u0438\u043d\u0430","sex":1,"screen_name":"id544097332","photo_50":"https:\/\/sun1-97.userapi.com\/c200416\/v200416429\/7de4\/wQLpJ2s0mJY.jpg?ava=1","photo_100":"https:\/\/sun1-17.userapi.com\/c200416\/v200416429\/7de3\/F-_9IunnnS4.jpg?ava=1","online":0,"online_info":{"visible":true,"last_seen":1578854878}},{"id":547543178,"first_name":"\u0421\u043e\u0431\u0430\u043a\u0430","last_name":"\u0423\u0434\u0430\u0447\u0438","sex":2,"screen_name":"pomolllnikfgb","photo_50":"https:\/\/sun1-85.userapi.com\/c200820\/v200820398\/1c3cd\/hOWzjK0InQ4.jpg?ava=1","photo_100":"https:\/\/sun1-99.userapi.com\/c200820\/v200820398\/1c3cc\/wsXyBLwDHOc.jpg?ava=1","online":0,"online_info":{"visible":false,"status":"recently"}}],"groups":[{"id":190687635,"name":"\u041f\u043e\u0434\u0441\u0447\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u0432 \u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438","screen_name":"club190687635","is_closed":1,"type":"group","photo_50":"https:\/\/vk.com\/images\/community_50.png?ava=1","photo_100":"https:\/\/vk.com\/images\/community_100.png?ava=1","photo_200":"https:\/\/vk.com\/images\/community_200.png?ava=1"}]}
Answer the question
In order to leave comments, you need to log in
VK API most likely already returns json! To decode you need to usejson_decode
Maxim Plotnikov You are using a very old version of the library, now everything can be done much more conveniently.
https://github.com/digitalstars/simplevk
Here is her github, there are examples and a link to the documentation
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question