With json_decode
and file_get_contents
you won’t be able to because it’s blocked.
My solution:
You can use a stream that will read the file and turn it into a string for use. See:
// abro uma stream com fopen
$stream = fopen("https://devjp.xyz/data.json", 'r');
$conteudo = stream_get_contents ($stream, -1); // insiro o conteúdo em uma variável
fclose($stream); // fecho o stream
// após pegar o conteúdo eu procuro a palavra 'mercadobitcoin'
// a partir de então o restante do conteúdo será resgatado a partir daquela palavra
$mercadobitcoin = strstr($conteudo, 'mercadobitcoin');
// a mesma coisa acontece aqui
$buy = strstr($mercadobitcoin, 'buy');
// separo para deixar apenas parte que interessa '$val[0]'
$val = explode(",", $buy);
// a mesma coisa, mas agora eu separo a string buy da string 32399.99
$valor = explode(":", $val[0]);
// mostro o valor
echo $valor[1]; // 32399.99
Unfortunately you will have a job to create a function that will standardize this.
I hope it helps you.
Helped yes ahhaha Thank you so much!! But this is a gambiarra or has no other method?
– João Pedro Morais
@Joãopedromorais is kind of a scam. Because the site blocked the use of
json_decode
.– Andrei Coelho
So the only way to use it is to treat the content as a string.
– Andrei Coelho
Parameters: format: (response format) -json -json-Cors (released for AJAX, requires key with correct domain) -php-serialize -debug (response in indented JSON, recommended for reading only)
– João Pedro Morais
In api has it, it means something?
– João Pedro Morais
@Joãopedromorais Probably yes. But I don’t know what it is. You need to see right how it configures, then it will be easier to pick up the values.
– Andrei Coelho
https://hgbrasil.com/status/finance/ am picking up from this site
– João Pedro Morais
@Joãopedromorais So I saw it needs a key to register there and put it on your site (application). There you will probably have easier access.
– Andrei Coelho
What is this json_decode lock? is something in the form of response or blocking by the server?
– João Pedro Morais
@Joãopedromorais both. The server blocks and the content you pick up comes with this lock.
– Andrei Coelho
@Joãopedromorais take a look. https://answall.com/questions/199199/como-prote-minha-aplica%C3%A7%C3%A3o-json
– Andrei Coelho
I created a key there for me, now as I know it’s releasing json_decode
– João Pedro Morais
I did!!! But I learned a lot about json from vc vlw msm! $json_data['Results']['bitcoin']['mercadobitcoin']['buy'];
– João Pedro Morais
it was just release the key there, I didn’t know there was this json lock Decode
– João Pedro Morais
@Joãopedromorais exact. I imagined that was it.
– Andrei Coelho
@Joãopedromorais quiet friend! Good luck! Hug!
– Andrei Coelho