Задать вопрос
@walkerstech

Не работает json_decode?

Вот пример кода
Сам json запрос
{"Envelope":{"Body":{"PaymentResponse":{"id":461735984,"attribute":[{"value":"RUB","key":"targetcurrencycode"},{"value":"2020-11-28T03:22:25.000+03:00","key":"yandexperformeddt"},{"value":"410017553711643","key":"yandexaccount"},{"value":"Выплата #161","key":"description"},{"value":"4","key":"typeid"},{"value":"-50","key":"sourceamount"},{"value":"Яндекс.Деньги","key":"targetalias"},{"value":"161","key":"clienttransaction"},{"value":" ","key":"errordescription"},{"value":"-1.5","key":"sourceamountfee"},{"value":"50","key":"targetamount"},{"value":"SUCCEED","key":"statusid"},{"value":"0","key":"haschildren"},{"value":"2020-11-28T03:22:25.000+03:00","key":"modified"},{"value":"13","key":"targetaccountid"},{"value":"services","key":"initby"},{"value":"WITHDRAWAL","key":"category"},{"value":"-51.5","key":"sourceamounttotal"},{"value":"RUB","key":"sourcecurrencycode"},{"value":"-51.5","key":"sourceaccounttotal"},{"value":"15422477","key":"sourceaccountid"}]}}}} { "Envelope": { "Header": { "Security": { "UsernameToken": { "Username": "", "Password": "" } } }, "Body": { "PaymentRequest": { "payer": "15422477", "payee": "13", "amount": "50", "isPayerAmount": true, "paymentPassword": "", "clientTransaction": "161", "description": "Выплата #161", "operationInfo": { "attribute": [ { "key": "YANDEXACCOUNT", "value": "410017553711643" } ] } } } } }


Сам код PHP
<?php
$json = '{"Envelope":{"Body":{"PaymentResponse":{"id":461735984,"attribute":[{"value":"RUB","key":"targetcurrencycode"},{"value":"2020-11-28T03:22:25.000+03:00","key":"yandexperformeddt"},{"value":"410017553711643","key":"yandexaccount"},{"value":"Выплата #161","key":"description"},{"value":"4","key":"typeid"},{"value":"-50","key":"sourceamount"},{"value":"Яндекс.Деньги","key":"targetalias"},{"value":"161","key":"clienttransaction"},{"value":" ","key":"errordescription"},{"value":"-1.5","key":"sourceamountfee"},{"value":"50","key":"targetamount"},{"value":"SUCCEED","key":"statusid"},{"value":"0","key":"haschildren"},{"value":"2020-11-28T03:22:25.000+03:00","key":"modified"},{"value":"13","key":"targetaccountid"},{"value":"services","key":"initby"},{"value":"WITHDRAWAL","key":"category"},{"value":"-51.5","key":"sourceamounttotal"},{"value":"RUB","key":"sourcecurrencycode"},{"value":"-51.5","key":"sourceaccounttotal"},{"value":"15422477","key":"sourceaccountid"}]}}}} { "Envelope": { "Header": { "Security": { "UsernameToken": { "Username": "", "Password": "" } } }, "Body": { "PaymentRequest": { "payer": "15422477", "payee": "13", "amount": "50", "isPayerAmount": true, "paymentPassword": "", "clientTransaction": "161", "description": "Выплата #161", "operationInfo": { "attribute": [ { "key": "YANDEXACCOUNT", "value": "410017553711643" } ] } } } } }';
$decode = json_decode($json);
echo $decode[0]['Envelope'];

выводить ничего
  • Вопрос задан
  • 220 просмотров
Подписаться 2 Простой Комментировать
Решения вопроса 1
alexey-m-ukolov
@alexey-m-ukolov Куратор тега PHP
  1. Это не валидный JSON.
    5fc605978618a757356440.png

  2. json_decode вторым аргументом принимает флаг формата и по-умолчанию возвращает объект, а вы работаете с ним, как с массивом.
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@none7
Не думаю, что echo может напрямую выводить массивы. Используйте var_dump.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы