PHP JSON Data Issue -


i'm trying fetch ask price bittrex api. i'm unable data. i've tried both of following , neither working:

function bittrex_mco_btc(){     $data = json_decode(getresource('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-mco'),'true');    return $data->result->ask;  }  function bittrex_mco_btc(){     $data = json_decode(getresource('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-mco'),'true');    return $data['result']['ask'];  } 

i think need use 'result' because it's associative array, have no idea what's wrong beyond that.

oh, here's getresource:

function getresource($url){ $ch = curl_init(); // setting curl options $timeout = 5; curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_connecttimeout, $timeout); curl_setopt($ch, curlopt_ssl_verifypeer, false);  $data = curl_exec($ch); curl_close($ch); return $data;} 

and here's json:

{"success":true,"message":"","result":[{"marketname":"btc-mco","high":0.00281740,"low":0.00162000,"volume":1490023.83431235,"last":0.00216002,"basevolume":3208.40974458,"timestamp":"2017-08-19t04:06:23.39","bid":0.00216001,"ask":0.00219186,"openbuyorders":953,"opensellorders":3453,"prevday":0.00278935,"created":"2017-07-02t00:37:16.957"}]} 

1st: should access . because ask key inside 0'th index .

2nd: json_decode second parameter should boolean value .but given string.

note: echo "<pre>"; print_r($data); understand structure of array.

php :

     $data = json_decode(getresource('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-mco'),true);      // $data = json_decode(file_get_contents('https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-mco'),true);       return $data['result'][0]['ask'];      }   ?> 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -