2016-07-10 6 views
1

에 액세스 할 수 없습니다. 반환 된 stdClass 배열에서 '제한'값을 가져 오려고합니다. 잘못된 액세스 오류 만 발생합니다. 잘못된 개체가 잘못된 배열은 아래 2 개 개의 별도 시도stdClass 배열 값 (PHP)

을 상쇄

코드 :

function callbittrex($url, $flags, $apikey, $apisecret){ 
     $nonce=time(); 
     if($flags == 0){ 
       $uri = $url.'?apikey='.$apikey.'&nonce='.$nonce; 
     } 
     if($flags == 1){ 
       $uri = $url; 
     } 
     $sign=hash_hmac('sha512',$uri,$apisecret); 
     $ch = curl_init($uri); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign)); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     $execResult = curl_exec($ch); 
     curl_close($ch); 
     $obj = json_decode($execResult); 
     return $obj; 

} 
$flags = 0; 
$url='https://bittrex.com/api/v1.1/market/getopenorders'; 
$myobj = callbittrex($url, $flags, $apikey, $apisecret); 
echo $myobj->result['0']->Limit; 

오류 :

PHP Notice: Undefined property: stdClass::$result in /home/buycoinz.php on line 31 

Notice: Undefined property: stdClass::$result in /home/buycoinz.php on line 31 
PHP Notice: Trying to get property of non-object in /home/buycoinz.php on line 31 

Notice: Trying to get property of non-object in /home/buycoinz.php on line 31 

갱신 : 맞춤법 오류 '결과'수정.

리턴 데이터 :

stdClass::__set_state(array(
    'success' => true, 
    'message' => '', 
    'result' => 
    array (
    0 => 
    stdClass::__set_state(array(
     'Uuid' => NULL, 
     'OrderUuid' => 'd880ed74-9da8-4725-8b4d-a02daa2d3a66', 
     'Exchange' => 'BTC-EXP', 
     'OrderType' => 'LIMIT_BUY', 
     'Quantity' => 2, 
     'QuantityRemaining' => 2, 
     'Limit' => 0.00053649999999999998, 
     'CommissionPaid' => 0, 
     'Price' => 0, 
     'PricePerUnit' => NULL, 
     'Opened' => '2016-07-06T12:12:37.377', 
     'Closed' => NULL, 
     'CancelInitiated' => false, 
     'ImmediateOrCancel' => false, 
     'IsConditional' => false, 
     'Condition' => 'NONE', 
     'ConditionTarget' => NULL, 
    )), 
    1 => 
    stdClass::__set_state(array(
     'Uuid' => NULL, 
     'OrderUuid' => '968bdd76-5cb2-4f80-9126-bc8fe6414e8a', 
     'Exchange' => 'BTC-EXP', 
     'OrderType' => 'LIMIT_BUY', 
     'Quantity' => 2, 
     'QuantityRemaining' => 2, 
     'Limit' => 0.00050000000000000001, 
     'CommissionPaid' => 0, 
     'Price' => 0, 
     'PricePerUnit' => NULL, 
     'Opened' => '2016-07-06T12:14:47.91', 
     'Closed' => NULL, 
     'CancelInitiated' => false, 
     'ImmediateOrCancel' => false, 
     'IsConditional' => false, 
     'Condition' => 'NONE', 
     'ConditionTarget' => NULL, 
    )), 
), 
)) 

초 시도 :

번호 :

function callbittrex($url, $flags, $apikey, $apisecret){ 
     $nonce=time(); 
     if($flags == 0){ 
       $uri = $url.'?apikey='.$apikey.'&nonce='.$nonce; 
     } 
     if($flags == 1){ 
       $uri = $url; 
     } 
     $sign=hash_hmac('sha512',$uri,$apisecret); 
     $ch = curl_init($uri); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign)); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     $execResult = curl_exec($ch); 
     curl_close($ch); 
     $obj = json_decode($execResult, true); 
     return $obj; 

} 
$flags = 0; 

$url='https://bittrex.com/api/v1.1/market/getopenorders'; 
$myobj = callbittrex($url, $flags, $apikey, $apisecret); 
foreach ($myobj as $dirobj){ 
     var_dump($dirobj['array'][0]); 
       //echo $dirobj['Limit']; 
} 

에러 :

NULL 
PHP Warning: Illegal string offset 'array' in /home/buycoinz.php on line 31 

Warning: Illegal string offset 'array' in /home/buycoinz.php on line 31 
PHP Notice: Uninitialized string offset: 0 in /home/buycoinz.php on line 31 

출력은 다음의 foreach() 루프가 stdClass 어레이 비활성화 표시 :

bool(true) 
string(0) "" 
array(2) { 
    [0]=> 
    array(17) { 
    ["Uuid"]=> 
    NULL 
    ["OrderUuid"]=> 
    string(36) "d880ed74-9da8-4725-8b4d-a02daa2d3a66" 
    ["Exchange"]=> 
    string(7) "BTC-EXP" 
    ["OrderType"]=> 
    string(9) "LIMIT_BUY" 
    ["Quantity"]=> 
    float(2) 
    ["QuantityRemaining"]=> 
    float(2) 
    ["Limit"]=> 
    float(0.0005365) 
    ["CommissionPaid"]=> 
    float(0) 
    ["Price"]=> 
    float(0) 
    ["PricePerUnit"]=> 
    NULL 
    ["Opened"]=> 
    string(23) "2016-07-06T12:12:37.377" 
    ["Closed"]=> 
    NULL 
    ["CancelInitiated"]=> 
    bool(false) 
    ["ImmediateOrCancel"]=> 
    bool(false) 
    ["IsConditional"]=> 
    bool(false) 
    ["Condition"]=> 
    string(4) "NONE" 
    ["ConditionTarget"]=> 
    NULL 
    } 
    [1]=> 
    array(17) { 
    ["Uuid"]=> 
    NULL 
    ["OrderUuid"]=> 
    string(36) "968bdd76-5cb2-4f80-9126-bc8fe6414e8a" 
    ["Exchange"]=> 
    string(7) "BTC-EXP" 
    ["OrderType"]=> 
    string(9) "LIMIT_BUY" 
    ["Quantity"]=> 
    float(2) 
    ["QuantityRemaining"]=> 
    float(2) 
    ["Limit"]=> 
    float(0.0005) 
    ["CommissionPaid"]=> 
    float(0) 
    ["Price"]=> 
    float(0) 
    ["PricePerUnit"]=> 
    NULL 
    ["Opened"]=> 
    string(22) "2016-07-06T12:14:47.91" 
    ["Closed"]=> 
    NULL 
    ["CancelInitiated"]=> 
    bool(false) 
    ["ImmediateOrCancel"]=> 
    bool(false) 
    ["IsConditional"]=> 
    bool(false) 
    ["Condition"]=> 
    string(4) "NONE" 
    ["ConditionTarget"]=> 
    NULL 
    } 
} 

이 stdClass 배열에서 '제한'값에 어떻게 액세스합니까?

답변

0

첫 번째 시도에서 결과 대신 을 얻으려고합니다. 두 번째 시도에서

(실제로, stdClass을 배열을하지 돌아올 때) 당신이 요청의 결과를 얻을 수 있습니다 간단하게 말해서 :

$result = callbittrex($url, $flags, $apikey, $apisecret)['result'];