1
1
15x032432018-09-16 14:07:22
PHP
15x03243, 2018-09-16 14:07:22

How to get all users from Json?

So there is Json:

"members": [
{
"user": {
"id": 1,
"username": "blabla1",
"level": 22,
"rank": "PLAYER",
"status": "MEMBER",
"guildCoins": 0,
"guildExp": 125
},
{
"user": {
"id": 2,
"username": "blabla2",
"level": 19,
"rank": "PLAYER",
"status": "MEMBER",
"guildCoins": 0,
"guildExp": 358
},
{
"user": {
"id": 3,
"username": "blablabla3",
"level": 31,
"rank": "PLAYER",
"playedSeconds": 2249862
"status": "MEMBER",
"guildCoins": 0,
"guildExp": 1130
},
{
"user": {
"id": 4
"username": "val12blabla,
"level": 20,
"rank": "PLAYER",
"playedSeconds": 1398004
"status": "OFFICER",
"guildCoins": 22817,
"guildExp": 4704
}]

If there are syntax errors, please correct me.
I need to get all users and display their username.
I write the following code: The same json is contained in it. But, doesn't work. Help. echo $obj_guild->members->user->{'username'};
$obj_guild

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2018-09-16
@KenKup

$obj = json_decode($data);
foreach ($obj->members as $member) {
    echo $member->user->username.PHP_EOL;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question