Fórum Como pegar uma string retornada da execução interna de uma URL e transformá-la em um objeto JSON? #571235
20/11/2016
0
O resultado da execução gera uma string no formato JSON:
{"success":false,"errorMessage":"Token inválido"}Como pegar a string retornada da execução interna da URL e transformá-la em um objeto JSON?
Diego Damasio
Curtir tópico
+ 0Posts
20/11/2016
Diego Damasio
$url = 'https://sandbox.boletobancario.com/boletofacil/integration/api/v1/fetch-payment-details?paymentToken='.$paymentToken; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url); // define que o conteúdo obtido deve ser retornado em vez de exibido curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); $order = curl_exec($ch); //Pega a string JSON obtida. curl_close($ch); $array = json_decode($order, true); //transforma a string em um array associativo.
Gostei + 0
21/11/2016
Kleber Araujo
se a requisição a essa Url for um simples Get, poderia também fazer da seguinte forma:
$url = 'https://sandbox.boletobancario.com/boletofacil/integration/api/v1/fetch-payment-details?paymentToken='.$paymentToken; $order = file_get_contents($url); $array = json_decode($order, true);
Gostei + 0
21/11/2016
Kleber Araujo
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)