How to decode values from javascript?

Asked

Viewed 55 times

0

Good night to all!! Guys, next, I’m getting the following variable from an application in angular:

   Array ( [{"nome":"volks","descricao":"conheça_o_novo_modelo_da_volks"}] => )

How can I convert it so that I can access its values? thank you all!! Horatio

Edited: This is the code that receives the data:

<?php
$dados = $_REQUEST;
print_r($dados);
/*
header('Content-Type: application/json charset=utf-8');
$x = array("info_recebida"=> $_REQUEST);
echo json_encode($x);

here momentarily I’m just exhibiting, and that’s where I brought the above variable

1 answer

1

Following the PHP manual, you can use the function json_decode

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));

Solution:

$dados = $_REQUEST;
// ou $dados = $_POST;
print_r(json_decode(dados));
  • so I did it this way, however, getting the data above, and the result was this: <br /> <b>Warning</b>: json_decode() expects Parameter 1 to be string, array Given in <b>C: xampp htdocs blog_da_corretora site wp-content themes slice_tema page-update_carro.php</b> on line <b>4</b><br /> NULL <br /> <b>Warning</b>: json_decode(expects) Parameter 1 to be string, array Given in <b>C: xampp htdocs blog_da_corretora site wp-content themes slice_tema page-update_carro.php</b> on line <b>5</b><br /> NULL

  • Edit the question and enter the code php

  • edited, I put the code you had sent, but then, I took and left only the display... in the view, it brings the Array ( [{"name":"Volks","Description":"known_o_novo_modelo_da_volks"}] => )

  • I edited the answer, try it the way I left it

  • so... I copied and pasted like this: <? php $dados = $_POST; // or $dados = $_POST; print_r(json_decode($dados)); the return was : Warning: json_decode() expects Parameter 1 to be string, array Given in C: xampp htdocs blog_da_corretora site wp-content themes slice_tema page-update_carro.php on line 4

  • got it...is the way I would go if I went with put...I thought I could do it the other way in the case of the post!! Thank you so much for the light, Wellington!! Big hug!!! Good night!!

Show 2 more comments

Browser other questions tagged

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