如何解析 Minecraft ops.json 以显示所有操作的用户、他们的 UUID 和操作用户的总数

How to parse Minecraft ops.json to display all oped users, their UUID's and the total amount of oped users

抱歉,如果这个标题没有意义,我对使用 PHP 中的 JSON 文件还很陌生。我几乎到处查看并多次改写我的问题,我得到的每个答案似乎都不适用于我的 JSON 文件,不确定 Minecraft 是否做了不同的事情或者我是否遗漏了什么。感谢任何对此做出回应的人!

目标

List all operators on my Minecraft Server on my website in a proper format with their UUID's and OP Level. I would also like to show the current amount of people OPed on the server.

Example Photo of what I imagine it looking like (of course with better CSS)

这是我的 PHP 代码

$serverdir = "../Minecraft Server/";
$json_url = $serverdir."ops.json";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);

<?php
foreach ($data as $value) {
  echo "$value <br>";
}

这段代码目前只输出数组 5 次我必须将 $data 更改为 $data[1-5] 以获得实际输出,但它会输出用户名、UUID 和级别,但我不知道如何格式化此类输出。

这是 JSON 文件

[
  {
    "uuid": "3afa9281-a239-453f-9538-49b57d9f2d06",
    "name": "Deathx90",
    "level": 2,
    "bypassesPlayerLimit": false
  },
  {
    "uuid": "461e6427-1d5c-43e3-b4ee-f8361884c3a2",
    "name": "Command_String",
    "level": 2,
    "bypassesPlayerLimit": false
  },
  {
    "uuid": "1ab6c2d3-6cae-4937-81af-cf348ca0f16c",
    "name": "sarcazsm",
    "level": 2,
    "bypassesPlayerLimit": false
  },
  {
    "uuid": "83619f6c-d259-4da2-868b-eba807e15b37",
    "name": "Monke_Syndrome",
    "level": 2,
    "bypassesPlayerLimit": false
  },
  {
    "uuid": "584f7a2f-2f8c-453e-a459-6ce8a683f04c",
    "name": "Kreyo813",
    "level": 2,
    "bypassesPlayerLimit": false
  }
]

解决后:

Here is the final product, I add some additional looks to it as well.

您也可以使用 php 对象表示法

$Object = json_decode($json);
foreach($Object as $obj){
    echo $obj->uuid,'<br>',
         $obj->name,'<br>',
         $obj->level,'<br>';
}

您可以使用计数来获取用户数量,仅供示例

$Object = json_decode($json);
$count = count($Object);

echo '<div><p>Number of OPed Users: (',$count,')</p></div>';
foreach($Object as $obj){
   echo '<div><p>',$obj->uuid,'<br>',
         $obj->name,'<br>',
         $obj->level,'</p></div><hr>';
}