How to parse an array of CURL json from the API Yandex.Direkt?

The lack of knowledge. Himself directorov, freelance.
It is necessary to spike a temporary solution to the conclusion of the accounts direct.
The output of the API you want to convert to HTML. The problem with the parsing of the array can not vduplit as.

<?php
$ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,'https://api.direct.yandex.ru/live/v4/json/');
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS,'{
 "method": "AccountManagement",
 "token": "AgAAAAA8-9-uAAVNXerAXgmXDkXquGRgLPMjN30",
 "param": {"SelectionCriteria": {}, "Action": "Get"}}'); //Post Fields
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $headers = [
 'POST /json/v5/ads/ HTTP/1.1',
 'Host: api.direct.yandex.com',
 'Authorization: Bearer AQAAAAAW-**********************************',
 'Accept-Language: EN',
 'Client-Login: *************@yandex.ru',
 'Content-Type: application/json; charset=utf-8',
];
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 $server_output = curl_exec ($ch);
 curl_close ($ch);

$balance = json_decode($server_output,true);

print_r ($balance);
echo $balance['Amount'];
echo $balance['AccountID'];
echo $balance['data']['AccountID'];
echo $balance['0']['AccountID'];


Displays
Array ( [data] => Array ( [ActionsResult] => Array ( ) [Accounts] => Array ( [0] => Array ( [Login] => pl4tpass [Discount] => 0 [Currency] => RUB [AmountAvailableForTransfer] => 0 [SmsNotification] => Array ( [MoneyOutSms] => No [PausedByDayBudgetSms] => Yes [The] => 21:00 [MoneyInSms] => No [The] => 09:00 ) [Amount] => 0 [AgencyName] => [EmailNotification] => Array ( [SendWarn] => [MoneyWarningValue] => 20 [PausedByDayBudget] => Yes [Email] => pl4tpass@yandex.ru ) [AccountID] => 49797112 ) ) ) )
April 7th 20 at 11:08
1 answer
April 7th 20 at 11:10
Solution
The formatting of the dump, lets not ask such "stupid" questions
That's so much better and it's clear from the structure of the array

Array ( 
 [data] => Array (
 [ActionsResult] => Array ( )
 [Accounts] => Array (
 [0] => Array ( 
 [Login] => pl4tpass 
 [Discount] => 0 
 [Currency] => RUB 
 [AmountAvailableForTransfer] => 0 
 [SmsNotification] => Array ( 
 [MoneyOutSms] => No
 [PausedByDayBudgetSms] => Yes
 [The] => 21:00
 [MoneyInSms] => No
 [The] => 09:00 
)
 [Amount] => 0 
 [AgencyName] => 
 [EmailNotification] => Array (
 [SendWarn] =>
 [MoneyWarningValue] => 20
 [PausedByDayBudget] => Yes
 [Email] => pl4tpass@yandex.ru
 ) 
 [AccountID] => 49797112 
 ) 
 ) 
 ) 
)


And once it is clear how to get to balance
$balance['data']['Accounts'][0]['Amount']
solution afloat. as it turned out. Thank you. I will learn the materiel. - ole_Beier commented on April 7th 20 at 11:13

Find more questions by tags PHPJSONYandex.Direct