J
J
JackShcherbakov2018-02-06 18:40:51
PHP
JackShcherbakov, 2018-02-06 18:40:51

Why can't I get data out of JSON?

Hello!
In this code, I receive JSON, which I then convert to a PHP object, but judging by the fact that nothing is displayed on the screen except for the JSON itself, I am doing something wrong. But what? Already times 20 revised the code.

<?php 
$params = array(
  "user_id" => 436580815,
  "v" => 5.52
);
$JSON = file_get_contents("https://api.vk.com/method/users.get?" . http_build_query($params)) . "<br>";
$result = json_decode($JSON); //со вторым аргументом true тоже не рабтоает
print $JSON."<br>";
print "Имя пользователя: " . $result->response[0]->first_name;

//print "https://api.vk.com/method/users.get?" . http_build_query($params);
?>

This is the JSON that comes in:
{"response":[{"id":436580815,"first_name":"Евгений","last_name":"Щербаков"}]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Rudkovsky, 2018-02-06
@JackShcherbakov

I suspect that the problem is in this line:
There is no need to add here . after that, your json will be appended and it will not be able to be processed by the function. "<br>"<br>json_decode

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question