Answer the question
In order to leave comments, you need to log in
How to parse JSON array from VK API?
Good day. I would like to implement such a thing that analyzes the last 10 messages, and if the message is not checked - we read what the user sent, and if the message, say, is found in the "Base", or at the moment - the Array, then we chose one of the actions that is appropriate for this message.
Let's skip the complexity, I need to get an array via CURL, there is a blank, everything works out, I get a json object, and immediately decode it.
<?php
$token = 'TOKEN';
$url = "https://api.vk.com/method/messages.get?out=0&offset=0&filtres=0&last_message_id=0&count=10&v=5.34&access_token=".$token."";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
$page = curl_exec($curl);
$exited = json_decode($page, true);
?>
Answer the question
In order to leave comments, you need to log in
Message text:
ID of the user who sent the message Message
IDs
In general, read the documentation for the methods, everything is VERY detailed in the contact api.
PS and yes, if you format the output of the code like this, you will be waiting for help for a very long time. I just know what the variables are and how they are called. Many in such a sheet of code will not even understand
PPS and one more point that I did not pay attention to, but as pointed out by jasonOk , specify json_decode($page); , i.e. without true
Uncertainty in this topic is caused by your lack of experience with JSON in principle.
For a better understanding, I recommend building some kind of array yourself and parsing it yourself.
In the world of APIs, the standard for issuing data for which is JSON, it is useful to be able to parse and assemble it yourself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question