S
S
Sergey2018-03-15 03:00:07
PHP
Sergey, 2018-03-15 03:00:07

How to accept json from php and test?

Must accept such data from the server

{
   "error":"ok",
   "result":{
      "amount":"1.00000000",
      "address":"YYY",
      "txn_id":"XXX",
      "confirms_needed":"10",
      "timeout":9000,
      "status_url":"https:\/\/www.site.net\/index.php?cmd=status&id=XXX&key=ZZZ"
      "qrcode_url":"https:\/\/www.site.net\/qrgen.php?id=XXX&key=ZZZ"
   }
}

I wrote this, but I don't know how to check
$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($json, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(is_array($val)) {
        echo "$key:\n";
    } else {
        echo "$key => $val\n";
    }
}

Tell me how to accept data, for example address and how to make such a request in php to test

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mysterion, 2018-03-15
@Mysterion

<?php

$json = '{
   "error":"ok",
   "result":{
      "amount":"1.00000000",
      "address":"YYY",
      "txn_id":"XXX",
      "confirms_needed":"10",
      "timeout":9000,
      "status_url":"https:\/\/www.site.net\/index.php?cmd=status&id=XXX&key=ZZZ",
      "qrcode_url":"https:\/\/www.site.net\/qrgen.php?id=XXX&key=ZZZ"
   }
}';

$output_std = json_decode($json);
echo $output_std->result->address;
$output_assoc = json_decode($json,true);
echo $output_assoc['result']['address'];

D
doublench21, 2018-03-15
@doublench21

I wrote so many
php, javascript, yii2, drupal, MQL, Android under the nickname
But I didn’t learn how to work with json ... sometimes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question