我正在使用rest API我需要解析一个永远改变的json结果

Okay so here goes i am using a rest api called strichliste i am creating a user credit payment system

i am trying to grab a users balance by username problems is my restapi i can only get the blanace via its userid

I have created a bit of php that grabs all the current users and the corresponding id and balance using this below

function getbal(){
    // Get cURL resource
    $curl = curl_init();
    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
                                 CURLOPT_RETURNTRANSFER => 1,
                                 CURLOPT_URL => 'https://example.io:8081/user/'
                                 )
                      );
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    // Close request to clear up some resources
    curl_close($curl);
    print_r($resp);
}

this is the resulting respinse i get after using this in my main php script

<? getbal(); ?>

result --- #

{  
   "overallCount":3,
   "limit":null,
   "offset":null,"entries":[
                            {"id":1,
                             "name":"admin",
                             "balance":0,
                             "lastTransaction":null
                            },
                            {"id":2,
                             "name":"pghost",
                             "balance":0,
                             "lastTransaction":null
                            },
                            {"id":3,
                             "name":"sanctum",
                             "balance":0,
                              "lastTransaction":null
                             }
                           ]
  }

as you can see there are only currently 3 users but this will grow everyday so the script needs to adapt to growing numbers of users

inside my php script i have a var with the currently logged in use so example

$user = "sanctum";

i want a php script that will use the output fro gatbal(); and only output the line for the given user in this case sanctum

i want it to output the line in jsondecode for the specific user

{"id":3,"name":"sanctum","balance":0,"lastTransaction":null}

can anyone help

$user = "sanctum";
$userlist = getbal();


function findUser($u, $l){
    if(!empty($l['entries'])){
      foreach($l['entries'] as $key=>$val){
         if($val['name']==$user){
             return $val;
         }
      }
    }
}

This way, once you have the list, and the user, you can just invoke findUser() by plugging in the userlist, and the user.

 $userData = findUser($user, $userlist);

However, I would suggest finding a way to get the server to return only the user you are looking for, instead of the whole list, and then finding based on username. But thats another discussion for another time.