A
A
Ayk722014-05-04 22:48:19
PHP
Ayk72, 2014-05-04 22:48:19

How to parse the code?

How to parse this code?

{"response":[{"id":55xxxxx,"first_name":"Сергей","last_name":"Сергеев","sex":2,"photo_max_orig":"url"}]}

How to extract everything separately?
Tried like this:
$user = json_decode($info, true);

$photo = $user['photo_max_orig'];

but didn't help.
Notice: Undefined index: photo_max_orig

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Rikcon, 2014-05-04
@Ayk72

Try $photo = $user->photo_max_orig
And in order to avoid such questions, you can see what's inside $user like this:
var_dump($user) or print_r($user) + it is desirable to wrap it in a tag for convenience - it will make the output more readable.

P
Petrusha Ukropov, 2014-05-04
@artishok

$user = json_decode($info, true);
$photo = $user->{'photo_max_orig'};

A
Ayk72, 2014-05-04
@Ayk72

Print_r:

Array ( [response] => Array ( [0] => Array ( [id] => 55xxxx [first_name] => Сергей [last_name] => Сергеев [sex] => 2 [screen_name] => id55xxxx [bdate] => 16.3.1994 [photo_max_orig] => url ) ) )

I
Ivan, 2014-05-05
@0neS

Just in case, comrade @Rickon above meant the pre tag. Something like:

<pre><?=var_dump($user)?></pre>
<pre><?=print_r($user)?></pre>

T
Terminaft, 2014-05-05
@Terminaft

Output all $user elements through foreach, then you will understand the structure of the vk api response
In general, for a photo, for example

$user = json_decode($info, true);
$photo = $user['response'][0]['photo_max_orig'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question