Iemand een idee hoe ik deze JSON in PHP krijg?
Iemand een idee hoe ik deze sjon in PHP krijg
Code (php)
1
{"players":{"c53ec47e-dc10-4908-950c-e7e91f8c938e":{"xp":14411,"profile_id":"c53ec47e-dc10-4908-950c-e7e91f8c938e","lootbox_probability":800,"level":49,"max_mmr":3129,"skill_mean":23.9427664492,"deaths":333,"next_rank_mmr":2400,"rank":11,"max_rank":16,"board_id":"pvp_ranked","skill_stdev":5.1317459682,"kills":112,"last_match_skill_stdev_change":-0.0227403775,"update_time":"2019-09-03T22:02:41.085000+00:00","last_match_mmr_change":-48,"abandons":1,"season":14,"last_match_skill_mean_change":-0.4864542875,"mmr":2394,"previous_rank_mmr":2300,"last_match_result":2,"wins":31,"region":"emea","losses":35,"nickname":"Sneeuwmonster","platform":"uplay","rankInfo":{"image":"https:\/\/i.imgur.com\/f68iB99.png","name":"Silver \u2161"}}}}
Alvast bedankt
Edit:
Titelfix en [code] en [/code] tags geplaatst.
Gewijzigd op 04/09/2019 18:30:59 door - Ariën -
Bedankt voor uw reactie, dat heb ik geprobeerd maar blijf als output Array krijgen.
Het feit dat je 'array' ziet wijst op het feit dat je het niet als array benadert. Wat doe je precies?
Gewijzigd op 04/09/2019 08:18:38 door - Ariën -
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
$data = '{"players":{"c53ec47e-dc10-4908-950c-e7e91f8c938e":{"xp":14411,"profile_id":"c53ec47e-dc10-4908-950c-e7e91f8c938e","lootbox_probability":800,"level":49,"max_mmr":3129,"skill_mean":23.9427664492,"deaths":333,"next_rank_mmr":2400,"rank":11,"max_rank":16,"board_id":"pvp_ranked","skill_stdev":5.1317459682,"kills":112,"last_match_skill_stdev_change":-0.0227403775,"update_time":"2019-09-03T22:02:41.085000+00:00","last_match_mmr_change":-48,"abandons":1,"season":14,"last_match_skill_mean_change":-0.4864542875,"mmr":2394,"previous_rank_mmr":2300,"last_match_result":2,"wins":31,"region":"emea","losses":35,"nickname":"Sneeuwmonster","platform":"uplay","rankInfo":{"image":"https:\/\/i.imgur.com\/f68iB99.png","name":"Silver \u2161"}}}}';
$data2 = json_decode($data, true);
echo "Parsing data by using PHP Array <br/>";
print_r($data2);
echo $data2["players"]."<br/>";
echo "<br/><br/> Players names are: <br/>";
foreach ($data2 as $data3) {
echo $data3['players']."<br/>";
}
?>
$data = '{"players":{"c53ec47e-dc10-4908-950c-e7e91f8c938e":{"xp":14411,"profile_id":"c53ec47e-dc10-4908-950c-e7e91f8c938e","lootbox_probability":800,"level":49,"max_mmr":3129,"skill_mean":23.9427664492,"deaths":333,"next_rank_mmr":2400,"rank":11,"max_rank":16,"board_id":"pvp_ranked","skill_stdev":5.1317459682,"kills":112,"last_match_skill_stdev_change":-0.0227403775,"update_time":"2019-09-03T22:02:41.085000+00:00","last_match_mmr_change":-48,"abandons":1,"season":14,"last_match_skill_mean_change":-0.4864542875,"mmr":2394,"previous_rank_mmr":2300,"last_match_result":2,"wins":31,"region":"emea","losses":35,"nickname":"Sneeuwmonster","platform":"uplay","rankInfo":{"image":"https:\/\/i.imgur.com\/f68iB99.png","name":"Silver \u2161"}}}}';
$data2 = json_decode($data, true);
echo "Parsing data by using PHP Array <br/>";
print_r($data2);
echo $data2["players"]."<br/>";
echo "<br/><br/> Players names are: <br/>";
foreach ($data2 as $data3) {
echo $data3['players']."<br/>";
}
?>
Array
(
[players] => Array
(
[c53ec47e-dc10-4908-950c-e7e91f8c938e] => Array
(
[xp] => 14411
[profile_id] => c53ec47e-dc10-4908-950c-e7e91f8c938e
[lootbox_probability] => 800
[level] => 49
[max_mmr] => 3129
[skill_mean] => 23.9427664492
[deaths] => 333
[next_rank_mmr] => 2400
[rank] => 11
[max_rank] => 16
[board_id] => pvp_ranked
[skill_stdev] => 5.1317459682
[kills] => 112
[last_match_skill_stdev_change] => -0.0227403775
[update_time] => 2019-09-03T22:02:41.085000+00:00
[last_match_mmr_change] => -48
[abandons] => 1
[season] => 14
[last_match_skill_mean_change] => -0.4864542875
[mmr] => 2394
[previous_rank_mmr] => 2300
[last_match_result] => 2
[wins] => 31
[region] => emea
[losses] => 35
[nickname] => Sneeuwmonster
[platform] => uplay
[rankInfo] => Array
(
[image] => https://i.imgur.com/f68iB99.png
[name] => Silver â…¡
)
)
)
)
Toevoeging op 04/09/2019 08:56:14:
Ik moet een mogelijkheid hebben om alleen de waarde "c53ec47e-dc10-4908-950c-e7e91f8c938e" uit players te krijgen. (alleen die waarde zonder haakjes of wat dan ook)
Je kunt twee dingen doen:
1) een foreach om door alle players heen te lopen.
2) de player er uit pakken door de unique id op te geven.
of:
Toevoeging op 04/09/2019 09:05:51:
Bij rankInfo gaan we nog een level dieper.. probeer het eens :-/
Gewijzigd op 04/09/2019 09:06:38 door Frank Nietbelangrijk
Hartelijk dank, ik geholpen met een goede oplossing!