Вызов PHP API, поиск значения ответаPhp

Кемеровские программисты php общаются здесь
Ответить
Гость
 Вызов PHP API, поиск значения ответа

Сообщение Гость »


I'm new to php and API calls, I'm trying to find the email address of my local MP using the parliament API (https://members-api.parliament.uk/index.html)
Challenge is, I can't return the email address directly. I can loop through the results of the call, but I want to return the email to a variable directly. The Problem seems to be in the set of results their is a [ value. (https://members-api.parliament.uk/api/M ... 02/Contact)
I can loop through the nodes and return a value but I cant see what the node value is itself to pull out the name

Код: Выделить всё

$url = 'https://members-api.parliament.uk/api/Members/'.$ID.'/Contact';
$get_data = callAPI('GET', $url, false);
$response = json_decode($get_data, true);

Код: Выделить всё

$email = $response["value"]["email"];

echo $email;
$ic = 0;
foreach ($response["value"] as $item) {
foreach ($item as $x){
//echo $item ;
//echo '
';
echo $item;
echo $item[$ic];
echo 'item
';
echo $x.'
';
$ic = $ic +1;
}
}


Источник: https://stackoverflow.com/questions/781 ... onse-value
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»