PDA

View Full Version : Problem with Json Decode in PHP



rafaelrp
27 May 2013, 7:12 PM
Hello!

I'm having a problem with json decode in my PHP server.. PHP5, linux

param:


data:{"cliId":""}



php decoded:


data:{\"cliId\":\"\"}


PHP put this "\" in the json and i can't get the array...

php code


$arrayResponse = json_decode($_REQUEST['data']);




Thanks! ~o)

tvanzoelen
27 May 2013, 11:00 PM
Hmm strange, you format half way




"data": {"cliId": ""}

semushin
27 May 2013, 11:24 PM
I solved this problem so:


list($files) = $db->sql_fetchrow($db->sql_query("SELECT files FROM *** WHERE id = ".$id));
// echo json from php to extjs
echo str_replace("\\", "", trim(html_entity_decode($files), "\""));

rafaelrp
28 May 2013, 4:51 AM
I solved this problem using this functions


$jsonEncoded = stripslashes($_REQUEST['data']);
$arrayResponse = json_decode($jsonEncoded);


But i don't think is the best way...

The best way is the php read the json without the "\"

Thanks! ~o)