sakhi Posted January 24, 2020 Share Posted January 24, 2020 I have json code and i want to prine only {"currency":"DOGE","available":"0","reserved":"420.000000000"} data. my json data [{"currency":"1ST","available":"0","reserved":"0"},{"currency":"DOGE","available":"0","reserved":"420.000000000"},{"currency":"ZSC","available":"0","reserved":"0"}] I use this code <?php $ch = curl_init('http://arbitrage.adquash.com/balance.json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json')); $return = curl_exec($ch); curl_close($ch); $result=json_decode($return); echo "<pre>"; foreach($result as $row){ echo $row->$a['currency']['available']['reserved']; ?> Quote Link to comment Share on other sites More sharing options...
gw1500se Posted January 24, 2020 Share Posted January 24, 2020 First, please use the code icon (<>) and select PHP for your code. The formatter makes it much easier to read. As for your question, PHP has a function to handle json called json_decode. It will create and associative array so you can access whatever you need easily. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 24, 2020 Share Posted January 24, 2020 echo $row->$a['currency']['available']['reserved']; I don't know where you're getting "$a" from but it doesn't belong there. If you print_r($row) you'll see what the value is. It's an object with "currency", "available", and "reserved" properties. Like any other object, you access them like ->currency. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.