W
W
walkerstech2020-12-01 11:50:42
PHP
walkerstech, 2020-12-01 11:50:42

json_decode not working?

Here is a sample code
The json request itself

{"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" } ] } } } } }


The PHP code itself
<?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'];

output nothing

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2020-12-01
@walkerstech

  1. This is not valid JSON.
    5fc605978618a757356440.png
  2. json_decode takes a format flag as its second argument and returns an object by default, and you work with it like an array.

N
none7, 2020-12-01
@none7

I don't think echo can output arrays directly. Use var_dump.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question