@KenKup
На другой планете.

Как разобрать данный массив?

Итак, есть JSON
JSON
{
"id": 8716,
"name": "TheTrailTeam",
"tag": null,
"color": "&f",
"level": 5,
"levelPercentage": 0.8118,
"totalCoins": 1062862,
"created": 1531656259,
"perks": {
"MEMBERS": {
"name": "Количество членов гильдии",
"level": 1
},
"COINS": {
"name": "Ежедневный лимит коинов",
"level": 2
},
"PARTY": {
"name": "Создание группы",
"level": 0
},
"MOTD": {
"name": "Приветственное сообщение",
"level": 0
},
"COINS_MULT": {
"name": "Дополнительный множитель коинов",
"level": 1
},
"TAG": {
"name": "Тег гильдии",
"level": 0
},
"COLOR": {
"name": "Цвет гильдии",
"level": 0
},
"GUILD_WAR": {
"name": "Гильдийные войны",
"level": 1
}
},
"members": [
{
"user": {
"id": 315609,
"username": "zvezda2003",
"level": 23,
"levelPercentage": 0.64407,
"rank": "PLAYER",
"playedSeconds": 2689375
},
"status": "MEMBER",
"joined": 1537026234,
"guildCoins": 0,
"guildExp": 2519
},
{
"user": {
"id": 581396,
"username": "Adski_Herobrin",
"level": 21,
"levelPercentage": 0.07506,
"rank": "PLAYER",
"playedSeconds": 1531876
},
"status": "MEMBER",
"joined": 1537000560,
"guildCoins": 6000,
"guildExp": 5120
},
{
"user": {
"id": 1913171,
"username": "xMertcanTR_2017",
"level": 20,
"levelPercentage": 0.28469,
"rank": "PLAYER",
"playedSeconds": 1483669
},
"status": "MEMBER",
"joined": 1538232845,
"guildCoins": 0,
"guildExp": 402
},
{
"user": {
"id": 1926672,
"username": "pokk12",
"level": 17,
"levelPercentage": 0.4507,
"rank": "PLAYER",
"playedSeconds": 1041846
},
"status": "MEMBER",
"joined": 1538232751,
"guildCoins": 0,
"guildExp": 1784
},
{
"user": {
"id": 2255968,
"username": "SS__228__SS",
"level": 32,
"levelPercentage": 0.71811,
"rank": "PLAYER",
"playedSeconds": 3500517
},
"status": "MEMBER",
"joined": 1536230094,
"guildCoins": 0,
"guildExp": 1668
},
{
"user": {
"id": 2314945,
"username": "pro_loki6666",
"level": 10,
"levelPercentage": 0.74784,
"rank": "PLAYER",
"playedSeconds": 461699
},
"status": "MEMBER",
"joined": 1538924585,
"guildCoins": 0,
"guildExp": 262
},
{
"user": {
"id": 2444749,
"username": "TheRigetPlay",
"level": 17,
"levelPercentage": 0.0475,
"rank": "PLAYER",
"playedSeconds": 883407
},
"status": "OFFICER",
"joined": 1535463406,
"guildCoins": 24225,
"guildExp": 2454
},
{
"user": {
"id": 2724926,
"username": "Alihan2013",
"level": 22,
"levelPercentage": 0.34391,
"rank": "PLAYER",
"playedSeconds": 2473565
},
"status": "LEADER",
"joined": 1534604717,
"guildCoins": 138000,
"guildExp": 33918
},
{
"user": {
"id": 2971928,
"username": "A6uJlbMaHCyp",
"level": 14,
"levelPercentage": 0.18755,
"rank": "PLAYER",
"playedSeconds": 855970
},
"status": "MEMBER",
"joined": 1536851389,
"guildCoins": 0,
"guildExp": 1886
},
{
"user": {
"id": 3040352,
"username": "demonchik47",
"level": 2,
"levelPercentage": 0.2219,
"rank": "PLAYER",
"playedSeconds": 5293
},
"status": "MEMBER",
"joined": 1538930730,
"guildCoins": 0,
"guildExp": 13
},
{
"user": {
"id": 3284887,
"username": "DizzyYT20",
"level": 9,
"levelPercentage": 0.781,
"rank": "PLAYER",
"playedSeconds": 101415
},
"status": "MEMBER",
"joined": 1538153981,
"guildCoins": 0,
"guildExp": 406
},
{
"user": {
"id": 3374195,
"username": "lexa2321",
"level": 18,
"levelPercentage": 0.4225,
"rank": "PLAYER",
"playedSeconds": 358067
},
"status": "MEMBER",
"joined": 1536493787,
"guildCoins": 0,
"guildExp": 7787
},
{
"user": {
"id": 3494688,
"username": "Aim4ikPLAY",
"level": 13,
"levelPercentage": 0.07968,
"rank": "PLAYER",
"playedSeconds": 220366
},
"status": "MEMBER",
"joined": 1538150646,
"guildCoins": 0,
"guildExp": 2656
},
{
"user": {
"id": 3649526,
"username": "DragonHeals",
"level": 15,
"levelPercentage": 0.56836,
"rank": "PLAYER",
"playedSeconds": 669101
},
"status": "MEMBER",
"joined": 1538930717,
"guildCoins": 0,
"guildExp": 763
},
{
"user": {
"id": 3654304,
"username": "_LoL_LoiZ_7777",
"level": 10,
"levelPercentage": 0.4413,
"rank": "PLAYER",
"playedSeconds": 309624
},
"status": "MEMBER",
"joined": 1537075393,
"guildCoins": 0,
"guildExp": 1257
},
{
"user": {
"id": 3706623,
"username": "Sanya1919",
"level": 12,
"levelPercentage": 0.47156,
"rank": "PLAYER",
"playedSeconds": 481326
},
"status": "MEMBER",
"joined": 1537076889,
"guildCoins": 0,
"guildExp": 6612
},
{
"user": {
"id": 3717626,
"username": "2_Steve47_2",
"level": 9,
"levelPercentage": 0.36108,
"rank": "PLAYER",
"playedSeconds": 241291
},
"status": "MEMBER",
"joined": 1535552273,
"guildCoins": 500,
"guildExp": 5311
},
{
"user": {
"id": 3766822,
"username": "Lama_blayt",
"level": 5,
"levelPercentage": 0.84156,
"rank": "PLAYER",
"playedSeconds": 27282
},
"status": "MEMBER",
"joined": 1538229292,
"guildCoins": 0,
"guildExp": 802
},
{
"user": {
"id": 3775624,
"username": "SiriouzGames",
"level": 6,
"levelPercentage": 0.93022,
"rank": "PLAYER",
"playedSeconds": 60625
},
"status": "MEMBER",
"joined": 1537616967,
"guildCoins": 0,
"guildExp": 1756
},
{
"user": {
"id": 3779236,
"username": "KILLYSADNO",
"level": 2,
"levelPercentage": 0.86979,
"rank": "PLAYER",
"playedSeconds": 2632
},
"status": "MEMBER",
"joined": 1537631491,
"guildCoins": 0,
"guildExp": 5
},
{
"user": {
"id": 3782079,
"username": "faeronsik",
"level": 3,
"levelPercentage": 0.66666,
"rank": "PLAYER",
"playedSeconds": 10690
},
"status": "MEMBER",
"joined": 1538231842,
"guildCoins": 0,
"guildExp": 11
},
{
"user": {
"id": 3785271,
"username": "McDezer",
"level": 4,
"levelPercentage": 0.81328,
"rank": "PLAYER",
"playedSeconds": 22372
},
"status": "MEMBER",
"joined": 1538196437,
"guildCoins": 0,
"guildExp": 255
}
]
}
>

Вы можете увидеть там массив "members". Дальше есть надпись "user". Внутри её можно увидеть поле "username".

Что-бы не перепутать, на скриншоте ниже показана часть массива "members".
СКРИНШОТ
5bc0de8183c2c583655642.png

Весь этот JSON (спйолер "JSON")находится в расшифрованном виде (json_decode) в $obj_guild.
Не могу разобраться, как можно с помощью например цикла foreach, провести "ряд действий" с каждым "username" по отдельности.

Заранее спасибо!
  • Вопрос задан
  • 80 просмотров
Решения вопроса 1
0xD34F
@0xD34F
ну, например:

foreach ($obj_guild['members'] as $m) {
  $username = $m['user']['username'];
  echo "$username - будет расстрелян<br>";
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы