![]() |
JSON PROB - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: JSON PROB (/showthread.php?tid=51850) |
JSON PROB - El Forum - 05-21-2012 [eluser]kptengco[/eluser] I've got a request data from other domain (json format). Its not empty or null and whenever i do this. Code: $_REQUEST['jsonData'] = '{"name":"Person 1"}'; //from other domain The question is why this Code: $dataDecoded->name; This is the request data from the other domain: Code: {"SC_MC":"00000000","SC_MID":"00000000","SC_AMOUNT":5000,"SC_REF":"0000","SC_PAYMODE":"Regular Installment","SC_PAYTERM":"12","SC_TRANSIP":"undefined","SC_PAYREF":"000000000000","SC_PAYDATE":"2012-05-21","SC_REFERRER":"https:\/\/abc.abc.com\/abc\/abc\/abc.php","SC_AGENT":"Mozilla\/5.0 (Windows NT 6.1; rv:12.0) Gecko\/20100101 Firefox\/12.0","SC_RRN":null,"SC_CUR_DATA":"PHP|1","SC_ORIG_AMOUNT":5000,"SC_STATUS":"approved"} is the data format wrong? JSON PROB - El Forum - 05-21-2012 [eluser]CroNiX[/eluser] Are you sure it's empty? You aren't echoing it out or doing anything with it. Basically you're just making a statement that has no action. Code: $dataDecoded->name; JSON PROB - El Forum - 05-21-2012 [eluser]kptengco[/eluser] im inserting it to a table and result is empty but when i insert this Code: $_REQUEST['jsonData'] it has its values Code: {"SC_MC":"00000000","SC_MID":"00000000","SC_AMOUNT":5000,"SC_REF":"0000" just like this Code: $dataDecoded = json_decode($_REQUEST['jsonData']); Code: "SELECT dataCode FROM tbl"; JSON PROB - El Forum - 05-22-2012 [eluser]kptengco[/eluser] Sorry my bad.. i figured it out by using Code: fwrite the data format was wrong when i open the file it display this data. Code: {\\\"SC_MC\\\":\\\"00000000\\\",\\\"SC_MID\\\":\\\"00000000\\\",\\\"SC_AMOUNT\\\":5000,\\\"SC_REF\\\":\\\"0000\\\" Too many trailing backslashes that i can't decode it. But when im inserting it to my table there's no backslashes. Then i try to output it in a file and i know now the prob btw thnx to your feedback CroNiX ![]() JSON PROB - El Forum - 05-22-2012 [eluser]CroNiX[/eluser] It's probably because you are using addslashes, which you shouldn't. If making your own insert query, use $this->db->escape($dataDecoded->name) to properly escape the variable. JSON PROB - El Forum - 05-22-2012 [eluser]kptengco[/eluser] i didn't use any Code: addslashes Code: json_encode($str,JSON_UNESCAPED_SLASHES) Code: $str = '{"name":"person 1"}'; The thing is im not the one who create the json data it just pass by my url and im the one who will decode it. So i don't have any idea that json data got a multiple backslashes. But, somethin' weird thou, i print it out Code: echo print_r($jsondata) Code: preg_replace I guess cURL method or watever method use for payment processing datafeed or (ipn) instant payment notification then pass that json or post/get data onto my url. (ex. PayPal) JSON PROB - El Forum - 05-22-2012 [eluser]CroNiX[/eluser] Kinda looked like you were using addslashes to me in post#2. Code: "INSERT INTO tbl (field1) VALUES('".addslashes($dataDecoded->name)." | ".$_REQUEST['jsonData']."')"; JSON PROB - El Forum - 05-22-2012 [eluser]kptengco[/eluser] oops sorry.. yea i did but i tried also not use it at first that was just a second test i add a Code: addslashes and a strip_tags also |