Jump to content

Help with Json


Go to solution Solved by Phi11W,

Recommended Posts

Hi
Can someone help me with this code?

<?php
//DOLLAR//
$json_dolar=llamar_api("https://mercados.ambito.com//dolar/informal/variacion");
        $dolar=$json_dolar;
        $compra=$dolar->compra;
        $venta=$dolar->venta;
        $variacion=$dolar->variacion;
        $fecha=$dolar->fecha;
        $var2=$dolar->class-variacion;
?>

This is OK
<?php echo ($compra); ?>

This is Not, probably 'cause de Hyphen
<?php echo ($class-variacion); ?>

Thanks

Link to comment
https://forums.phpfreaks.com/topic/314388-help-with-json/
Share on other sites

First, please use the code icon (<>) in the menu and specify PHP for your code. You don't say what error your are getting but that syntax is probably wrong. You don't show how $class is defined but as a guess given almost no information from you I'd say you want this:

<?php echo ($class->variacion); ?>

 

Link to comment
https://forums.phpfreaks.com/topic/314388-help-with-json/#findComment-1593170
Share on other sites

Of course, the correct code could equally be

echo ($class - $variacion);

or

echo ($class_variacion);

but who can say as we have no idea what the line is supposed to do.

"'cause de Hyphen" doesn't really cut it as an explanation.

Link to comment
https://forums.phpfreaks.com/topic/314388-help-with-json/#findComment-1593173
Share on other sites

5 hours ago, Sunnyisles said:

I just need to echo class-variacion from this url https://mercados.ambito.com//dolar/informal/variacion

This doesn't use your api but if page is always formatted that way then possibly
 

 <?php
//DOLLAR//
    $json_dolar=file_get_contents("https://mercados.ambito.com//dolar/informal/variacion");
   
   $dolar=explode("\",", substr_replace(trim($json_dolar, '{}') ,"",-1));
        
	echo trim(explode("\":\"", $dolar[4])[1])."<br><br>";
	
	foreach($dolar as $key => $value){
		echo $value." OR ".trim(explode("\":\"", $dolar[$key])[1])."<br>";
	}

?>

Which displays

 

up

"compra":"202,50 OR 202,50
"venta":"206,50 OR 206,50
"fecha":"04\/01\/2022 - 16:45 OR 04\/01\/2022 - 16:45
"variacion":"0,24% OR 0,24%
"class-variacion":"up OR up

 

Edited by dodgeitorelse3
Link to comment
https://forums.phpfreaks.com/topic/314388-help-with-json/#findComment-1593178
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.