2013-05-06 2 views
0

je suis en train de se connecter l'activité de MtGox en utilisant leur api, ils fournissent une chaîne standard JSON http://data.mtgox.com/api/2/BTCUSD/money/tickerTirer partie spécifique de chaîne JSON avec php

maintenant ce que je l'utilise pour mettre réellement tout en un tableau bien organisés

$url = 'http://data.mtgox.com/api/2/BTCUSD/money/ticker'; 
$json = file_get_contents($url); 
$obj = json_decode($json, true); 

MAIS, alors je ne peux pas comprendre comment je peux tirer des détails spécifiques comme, Haute> Valeur. plutôt que je me force à aller le long chemin en imprimant tout en utilisant la boucle suivante:

foreach($obj as $arr) { 
if (is_array($arr)) { 
foreach($arr as $arry) { 
if (is_array($arry)) { 
      $query_insert_json = "INSERT INTO currency(currency, currentValue, highValue, lowValue) VALUES('USD', '$arry[value]', '12.987', '9.452')"; 
      $result_insert_json = mysqli_query($dbc, $query_insert_json); 
      if (!$result_insert_json) { 
       echo 'Query Failed '; 
      } 
echo <<<END 
<tr> 
<td align="center">$arry[value]</td> 
<td align="center">$arry[value_int]</td> 
<td align="center">$arry[display]</td> 
<td align="center">$arry[display_short]</td> 
<td align="center">$arry[currency]</td> 
</tr> 
END; 

Répondre

0

Comme cela? pull specific details like, High>Value

<?php 
$json=file_get_contents("http://data.mtgox.com/api/2/BTCUSD/money/ticker"); 
$json=json_decode($json,true); 

echo $json['data']['high']['value']; 
?> 

Si vous voulez trouver les données à tirer, voir la source en print_r($json), puis regardez-le:

array

Chaque indentation est un autre niveau, en regardant le premier niveau, il est data, puis aller à la seconde, il est high, puis enfin value.

+0

C'est exactement ce dont j'avais besoin, merci mille fois. –

Questions connexes