How do I get reply json in php?

Asked

Viewed 157 times

0

I have the link:

https://dominio.com/apiJSON.php?data={"login":"[email protected]","senha":"Minhasenha","campanha":"ID 1234","mensagens":{"1":{"numero":2799999999,"msg":"Uma mensagem qualquer","data":"2015-10-19 01:07:52"}}}

Pasting this link in the browser with the correct parameters gets the following answer in the browser:

{"tip":1,"msg":[{"numero":2799999999,"id":"1234","status":1}]}

I want to take this answer and work it with php or javascrpit, whatever. But I need to get this information. Can someone help me? Thank you!!!

  • You can use a get, to get the date, then you can use a $var = json_decode($_GET[data]) and a print_r($var) to see rsrs

  • Oops, I’ll try here, friend and I’ll answer

  • @Thiago if you have already solved the problem with any of the answers below, you can demonstrate this by marking the answer as accepted by clicking on V on the left side. If you have found another different solution, you can post the solution as a response, and mark as accepted as well.

2 answers

2


Long live,

$data = file_get_contents('www.meusite.com');
$data = json_decode($data,true); 

From there it’s like you have a normal array..

Probably in your case you’ll have to use: http://php.net/manual/en/function.urlencode.php

file_get_contents('dominio.com/apiJSON.php?data='.urlencode(';{"login":"e‌​[email protected]","senha":"Minhasenha","campanha":"ID 1234","mensagens":{"1":{"numero":2799999999,"msg":"Uma mensagem qualquer","data":"2015-10-19 01:07:52"}}}')) 

Because you have special characters. (you can always send this data by post instead of query string)

Any doubt warns ;)

  • Whoa, buddy, I’ll try here and warn. VLW

  • This returning me the following error: failed to open stream: HTTP request failed!

  • You have tried: file_get_contents('www.dominio.com/apiJSON.php? data='. urlencode('{"login":"[email protected]","password":"Minhasenha","campaign":"ID 1234","messages":{"1":{"numero":2799999,"msg":"Any message","date":"2015-10-19 01:07:52"}}}'))

  • I’ll try here friends, already I answer!

  • Friends, it worked. It’s returning me an array. Does anyone know how I got each element of the array? Thanks!!!

  • uses a foreach() to take the data from the... foreach($given as $value){ echo $value->return name_do_name; }

  • Opa got friends, thank you all. Coloco solved?

  • I’m glad you made it ;)

Show 3 more comments

0

$data = file_get_contents('www.meusite.com'); $data = json_decode($date);

Try it like this :P

Browser other questions tagged

You are not signed in. Login or sign up in order to post.