bookerbb Posted September 2, 2015 Share Posted September 2, 2015 I have a problem and do not know what the problem is. I have a javascript variable in my html. which is var people = '{"names": ["Matthew", "Lucas", "Todd", "Roxie", "Kyle", "Ken", "Gideon"], "surnames": ["Patel", "Lee", "Ingram", "Richter", "Katayanagi", "Katayanagi", "Graves"]}'; I parse the variable on one function in my script and use it. Everything works fine. var mydata = JSON.parse(people); But then I need to send the data to a php file, I send it by wrtting the data to a hidden input. var strObject = JSON.stringify(mydata); var replaced = strObject.replace(/\//g, ''); oFormObject = document.forms['theForm']; oFormObject.elements["jsonData"].value = replaced; After which I try to encode it in my decode.php using: $obj = $_POST['jsonData']; $p = json_decode($obj); var_dump($p); But when I do a var_dump($s) I get this NULL as output. Quote Link to comment https://forums.phpfreaks.com/topic/298018-json-in-php-not-working/ Share on other sites More sharing options...
Ch0cu3r Posted September 2, 2015 Share Posted September 2, 2015 What is the contents of $_POST? var_dump($_POST); Quote Link to comment https://forums.phpfreaks.com/topic/298018-json-in-php-not-working/#findComment-1520117 Share on other sites More sharing options...
requinix Posted September 2, 2015 Share Posted September 2, 2015 Why did you remove the slashes from the JSON string? Quote Link to comment https://forums.phpfreaks.com/topic/298018-json-in-php-not-working/#findComment-1520118 Share on other sites More sharing options...
scootstah Posted September 2, 2015 Share Posted September 2, 2015 Try echo json_last_error_msg() after json_decode() Quote Link to comment https://forums.phpfreaks.com/topic/298018-json-in-php-not-working/#findComment-1520130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.