JSON data cannot be accessed in PHP version 5.2.17 - php

the JSON passes string in the following format:
params{"visitor":"","submitted":"submitted","date":"02/28/2015"}
now the problem,
I am trying to check in in my PHP file the "visitor", "submitted" and "date", but all of it comes empty for some reason. I have also tried the following:
$json = $_POST['params'];
var_dump(json_decode($json));
but the result is NULL
can you please help me a little as I have tried almost everything that I could possibly try but nothing worked so far.
also if I am doing var_dump($_POST['params']); then I get the following:
string(1035) "{\"visitor\":\"\",\"submitted\":\"submitted\",\"date\":\"02/28/2015\"}"

Working on PHP 5.2.17 you must need to use stripslashes() with the $_POST variable like this $post = json_decode(stripslashes($_POST['data']));
Hope it helps

Related

json_decode in php retruns null

i am trying to parse json its working in online website but not working on json_decode() php, below is my json.
{"category":"group_channel:message_send","sender":{"nickname":"Four Six","user_id":"917777770046","profile_url":"https:\/\/sendbird.com\/main\/img\/profiles\/profile_05_512px.png","metadata":{}},"custom_type":"application\/octet-stream","mention_type":"users","mentioned_users":[],"app_id":"C14BC2EA-ED60-4A82-9441-5C312A6EA991","members":[{"is_blocking_sender":false,"unread_message_count":1,"total_unread_message_count":1,"is_active":true,"is_online":true,"is_hidden":0,"channel_mention_count":0,"nickname":"Four Six","is_blocked_by_sender":false,"user_id":"917777770046","channel_unread_message_count":0,"state":"joined","push_enabled":true,"push_trigger_option":true,"profile_url":"https:\/\/sendbird.com\/main\/img\/profiles\/profile_05_512px.png","metadata":{}}],"type":"MESG","payload":{"custom_type":"application\/octet-stream","created_at":1570690168039,"translations":{},"message":"H4sIAAAAAAAAALWTXYucMBSG\/4rkWockRh3nrrNlYViYFpbSyyUmx5mwmkiMpXaZ\/94T54MpC6Ut\nVASPb3Ke85W8kR7GUR5gp8mGCOCUFm2V6aIpMqHKOpOqEVnRasYbJbhqZFbqNeNFVWdlK1QmqoZm\nUqO+VrpSDLgStCApab3rEVmzankoFSWqYR4A1UvQl9b5HlV1lOGPE8D9g5w7J9HhjSyEy\/eMoAx3\njAEGsmEpAW0CWNl0Mew++nYyPC5ORFrtndEofgM\/GmdRi87KWfQJEYu0FYuGlkHGb+8a08F+6hvw\n78trjR\/DXvYx2KObPEqdvCnP5jsK0EvT4R+aUmuPnUDuKSUHsHphLunLMI1nGyPDp3ZrfDiehcG7\nFnP4bFSYPHzxF1g\/72zroo2w3mnTGtDb+X2S17UPWCErKlrWlDG65hX6xXr5fb0xOiI4ZXXGKL7\/\nSl9f6Pk9\/dYA8pTltUiTbefUa\/KUJs9H+Tr5YfLJg+ucne+UNPkI3dGkCXJpjk47q41cWo0x+XpV\n1oyWeY6CPZBNVa2YKHLBKpysCTHlvcNmJl9hDGfUMvPJBh8Xr7Q4g1j6dccPM8TzscRclj1AeLGX\n0V6Tu2\/PLy2oc178rnOn6Pif7qIZH1w\/dBAgkmfy9xMsebpcsdvBZ5jw6SfcNiZDPgQAAA==\n","data":"message_form","message_id":2839079954},"channel":{"is_distinct":false,"name":"KPGI Workday","custom_type":"kpgi_workday_data","is_ephemeral":false,"channel_url":"sendbird_group_channel_150279781_505f37b8b653c01febe37245d447f7098d0fe53c","is_public":false,"is_super":false,"data":"{\"chatApp\":\"sendbird\",\"chatId\":\"4e2005f7-d5b5-4c69-acb4-5fd12bc42cba\",\"topParentId\":\"4e2005f7-d5b5-4c69-acb4-5fd12bc42cba\",\"formNumber\":\"0\",\"creatorName\":\"Four Six\",\"creatorId\":\"917777770046\",\"topic\":\"KPGI Workday\",\"formstatus\":\"{\\\"kpgi_workday_travel_form\\\":0,\\\"kpgi_workday_initiate_break\\\":0,\\\"kpgi_workday_travel\\\":0,\\\"kpgi_workday_expense\\\":0,\\\"kpgi_workday_close_data\\\":0,\\\"kpgi_workday_timesheet\\\":0}\",\"type\":\"kpgi_workday_data\",\"parentId\":\"\"}","is_discoverable":false},"sdk":"Android"}
Please try this JSON:
{"category":"group_channel:message_send","sender":{"nickname":"Four Six","user_id":"917777770046","profile_url":"https://sendbird.com/main/img/profiles/profile_05_512px.png","metadata":{}},"custom_type":"application/octet-stream","mention_type":"users","mentioned_users":[],"app_id":"C14BC2EA-ED60-4A82-9441-5C312A6EA991","members":[{"is_blocking_sender":false,"unread_message_count":1,"total_unread_message_count":1,"is_active":true,"is_online":true,"is_hidden":0,"channel_mention_count":0,"nickname":"Four Six","is_blocked_by_sender":false,"user_id":"917777770046","channel_unread_message_count":0,"state":"joined","push_enabled":true,"push_trigger_option":true,"profile_url":"https://sendbird.com/main/img/profiles/profile_05_512px.png","metadata":{}}],"type":"MESG","payload":{"custom_type":"application/octet-stream","created_at":1570690168039,"translations":{},"message":"H4sIAAAAAAAAALWTXYucMBSG/4rkWockRh3nrrNlYViYFpbSyyUmx5mwmkiMpXaZ/94T54MpC6Ut\nVASPb3Ke85W8kR7GUR5gp8mGCOCUFm2V6aIpMqHKOpOqEVnRasYbJbhqZFbqNeNFVWdlK1QmqoZm\nUqO+VrpSDLgStCApab3rEVmzankoFSWqYR4A1UvQl9b5HlV1lOGPE8D9g5w7J9HhjSyEy/eMoAx3\njAEGsmEpAW0CWNl0Mew++nYyPC5ORFrtndEofgM/GmdRi87KWfQJEYu0FYuGlkHGb+8a08F+6hvw\n78trjR/DXvYx2KObPEqdvCnP5jsK0EvT4R+aUmuPnUDuKSUHsHphLunLMI1nGyPDp3ZrfDiehcG7\nFnP4bFSYPHzxF1g/72zroo2w3mnTGtDb+X2S17UPWCErKlrWlDG65hX6xXr5fb0xOiI4ZXXGKL7/\nSl9f6Pk9/dYA8pTltUiTbefUa/KUJs9H+Tr5YfLJg+ucne+UNPkI3dGkCXJpjk47q41cWo0x+XpV\n1oyWeY6CPZBNVa2YKHLBKpysCTHlvcNmJl9hDGfUMvPJBh8Xr7Q4g1j6dccPM8TzscRclj1AeLGX\n0V6Tu2/PLy2oc178rnOn6Pif7qIZH1w/dBAgkmfy9xMsebpcsdvBZ5jw6SfcNiZDPgQAAA==\n","data":"message_form","message_id":2839079954},"channel":{"is_distinct":false,"name":"KPGI Workday","custom_type":"kpgi_workday_data","is_ephemeral":false,"channel_url":"sendbird_group_channel_150279781_505f37b8b653c01febe37245d447f7098d0fe53c","is_public":false,"is_super":false,"data":"{\"chatApp\":\"sendbird\",\"chatId\":\"4e2005f7-d5b5-4c69-acb4-5fd12bc42cba\",\"topParentId\":\"4e2005f7-d5b5-4c69-acb4-5fd12bc42cba\",\"formNumber\":\"0\",\"creatorName\":\"Four Six\",\"creatorId\":\"917777770046\",\"topic\":\"KPGI Workday\",\"formstatus\":\"{\"kpgi_workday_travel_form\":0,\"kpgi_workday_initiate_break\":0,\"kpgi_workday_travel\":0,\"kpgi_workday_expense\":0,\"kpgi_workday_close_data\":0,\"kpgi_workday_timesheet\":0}\",\"type\":\"kpgi_workday_data\",\"parentId\":\"\"}","is_discoverable":false},"sdk":"Android"}
I have made some edits. If this works, you can do a string compare to see the differences, but overall, I just deleted some extra slashes.

Can't get data from json

I need to get brand: "hello world"
When I send using post data with json and get it with
$input = Input::all();
then with
die(print_r($input));
this is written
Array ([[], {brand: "hello world"}, [], 1427154586016])1
And
I tryed using json_encode and get with
die(print_r($encode));
this
{data: "{"brand":"Hello world"}", dc: "142715"}1
now if I do
$brand = $encode['data'] or $brand = $encode['brand']
I get an error.
How do I get Hello world to var $brand
It looks like you're using json_encode() when you should be using json_decode(). But like kamlesh pointed out, it appears that your original JSON data is not valid JSON to begin with, so this would not help you. This wiki article has an example of valid syntax.
Also, if you're using laravel, you can use the helper function dd(), which will die() and var_dump() automatically for you, saving you a bit of time.
Hopefully this solves your problem, but if not, read the docs for the Input. There should be something there to get you on the right track.

PHP says that this json is invalid because "object property name separator ':' expected", can anyone see why?

What's wrong with this json:
{ "items" : [ {"timestamp":"1372964400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1373666400","value":"2","nid":"593141","platform":"-1"},{"timestamp":"1371398400","value":"1","nid":"34872","platform":"-1"},{"timestamp":"1374238800","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1371902400","value":"1","nid":"79534","platform":"-1"},{"timestamp":"1373425200","value":"1","nid":"583657","platform":"-1"},{"timestamp":"1376251200","value":"4","nid":"701275","platform":"-1"},{"timestamp":"1371330000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372183200","value":"1","nid":"81447","platform":"-1"},{"timestamp":"1372348800","value":"2","nid":"83560","platform":"-1"},{"timestamp":"1373162400","value":"1","nid":"583657","platform":"-1"},{"timestamp":"1374174000","value":"2","nid":"607389","platform":"-1"},{"timestamp":"1371834000","value":"2","nid":"79534","platform":"-1"},{"timestamp":"1372723200","value":"1","nid":"190555","platform":"-1"},{"timestamp":"1373385600","value":"2","nid":"590502","platform":"-1"},{"timestamp":"1375855200","value":"1","nid":"697831","platform":"-1"},{"timestamp":"1372312800","value":"1","nid":"81447","platform":"-1"},{"timestamp":"1373047200","value":"2","nid":"545517","platform":"-1"},{"timestamp":"1373929200","value":"3","nid":"605563","platform":"-1"},{"timestamp":"1375462800","value":"1","nid":"647466","platform":"-1"},{"timestamp":"1376434800","value":"5","nid":"704771","platform":"-1"},{"timestamp":"1371722400","value":"1","nid":"79534","platform":"-1"},{"timestamp":"1372240800","value":"1","nid":"82257","platform":"-1"},{"timestamp":"1372687200","value":"1","nid":"190555","platform":"-1"},{"timestamp":"1373367600","value":"1","nid":"590502","platform":"-1"},{"timestamp":"1374634800","value":"1","nid":"610377","platform":"-1"},{"timestamp":"1375812000","value":"1","nid":"697482","platform":"-1"},{"timestamp":"1372129200","value":"1","nid":"81157","platform":"-1"},{"timestamp":"1372287600","value":"1","nid":"79568","platform":"-1"},{"timestamp":"1372989600","value":"1","nid":"40191","platform":"-1"},{"timestamp":"1373788800","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1375376400","value":"1","nid":"646893","platform":"-1"},{"timestamp":"1376420400","value":"1","nid":"704624","platform":"-1"},{"timestamp":"1371423600","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372230000","value":"7","nid":"81447","platform":"-1"},{"timestamp":"1372413600","value":"1","nid":"118275","platform":"-1"},{"timestamp":"1373306400","value":"5","nid":"590502","platform":"-1"},{"timestamp":"1374264000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1371960000","value":"1","nid":"79568","platform":"-1"},{"timestamp":"1372924800","value":"1","nid":"82456","platform":"-1"},{"timestamp":"1373558400","value":"3","nid":"590502","platform":"-1"},{"timestamp":"1375092000","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1376280000","value":"1","nid":"701529","platform":"-1"},{"timestamp":"1370044800","value":"1","nid":"68566","platform":"-1"},{"timestamp":"1371380400","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372183200","value":"3","nid":"81457","platform":"-1"},{"timestamp":"1372352400","value":"1","nid":"83613","platform":"-1"},{"timestamp":"1373194800","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1375689600","value":"1","nid":"687547","platform":"-1"},{"timestamp":"1371902400","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1372762800","value":"1","nid":"212931","platform":"-1"},{"timestamp":"1375977600","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1371322800","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1372179600","value":"1","nid":"81457","platform":"-1"},{"timestamp":"1372345200","value":"2","nid":"83560","platform":"-1"},{"timestamp":"1373068800","value":"1","nid":"545517","platform":"-1"},{"timestamp":"1374163200","value":"1","nid":"607389","platform":"-1"},{"timestamp":"1375470000","value":"1","nid":"647526","platform":"-1"},{"timestamp":"1376460000","value":"1","nid":"705149","platform":"-1"},{"timestamp":"1370278800","value":"1","nid":"57508","platform":"-1"},{"timestamp":"1371765600","value":"2","nid":"79568","platform":"-1"},{"timestamp":"1372690800","value":"1","nid":"212147","platform":"-1"},{"timestamp":"1373382000","value":"9","nid":"590502","platform":"-1"},{"timestamp":"1374674400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1375819200","value":"1","nid":"697482","platform":"-1"},{"timestamp":"1371132000","value":"1","nid":"76647","platform":"-1"},{"timestamp":"1372143600","value":"1","nid":"81209","platform":"-1"},{"timestamp":"1372302000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1373036400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1373886000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1375380000","value":"1","nid":"646893","platform":"-1"},{"timestamp":"1376427600","value":"1","nid":"704735","platform":"-1"},{"timestamp":"1370260800","value":"3","nid":"68984","platform":"-1"},{"timestamp":"1372240800","value":"1","nid":"82162","platform":"-1"},{"timestamp":"1372428000","value":"1","nid":"154915","platform":"-1"},{"timestamp":"1373364000","value":"6","nid":"590502","platform":"-1"},{"timestamp":"1374606000","value":"1","nid":"610377","platform":"-1"}] }
when running json_decode on this string php returns null.
i've checked with every online php json_decoder and they decode it succesfully.
i've also tried with json_decode($json, TRUE); but the call also returns NULL
i'm on php version PHP 5.5.1-2+debphp.org~precise+2
I've checked what json_last_error_msg() has to say and it returned:
object property name separator ':' expected
This works fine for me under 5.4.3
<?php
$json = '{ "items" : [ {"timestamp":"1372964400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1373666400","value":"2","nid":"593141","platform":"-1"},{"timestamp":"1371398400","value":"1","nid":"34872","platform":"-1"},{"timestamp":"1374238800","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1371902400","value":"1","nid":"79534","platform":"-1"},{"timestamp":"1373425200","value":"1","nid":"583657","platform":"-1"},{"timestamp":"1376251200","value":"4","nid":"701275","platform":"-1"},{"timestamp":"1371330000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372183200","value":"1","nid":"81447","platform":"-1"},{"timestamp":"1372348800","value":"2","nid":"83560","platform":"-1"},{"timestamp":"1373162400","value":"1","nid":"583657","platform":"-1"},{"timestamp":"1374174000","value":"2","nid":"607389","platform":"-1"},{"timestamp":"1371834000","value":"2","nid":"79534","platform":"-1"},{"timestamp":"1372723200","value":"1","nid":"190555","platform":"-1"},{"timestamp":"1373385600","value":"2","nid":"590502","platform":"-1"},{"timestamp":"1375855200","value":"1","nid":"697831","platform":"-1"},{"timestamp":"1372312800","value":"1","nid":"81447","platform":"-1"},{"timestamp":"1373047200","value":"2","nid":"545517","platform":"-1"},{"timestamp":"1373929200","value":"3","nid":"605563","platform":"-1"},{"timestamp":"1375462800","value":"1","nid":"647466","platform":"-1"},{"timestamp":"1376434800","value":"5","nid":"704771","platform":"-1"},{"timestamp":"1371722400","value":"1","nid":"79534","platform":"-1"},{"timestamp":"1372240800","value":"1","nid":"82257","platform":"-1"},{"timestamp":"1372687200","value":"1","nid":"190555","platform":"-1"},{"timestamp":"1373367600","value":"1","nid":"590502","platform":"-1"},{"timestamp":"1374634800","value":"1","nid":"610377","platform":"-1"},{"timestamp":"1375812000","value":"1","nid":"697482","platform":"-1"},{"timestamp":"1372129200","value":"1","nid":"81157","platform":"-1"},{"timestamp":"1372287600","value":"1","nid":"79568","platform":"-1"},{"timestamp":"1372989600","value":"1","nid":"40191","platform":"-1"},{"timestamp":"1373788800","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1375376400","value":"1","nid":"646893","platform":"-1"},{"timestamp":"1376420400","value":"1","nid":"704624","platform":"-1"},{"timestamp":"1371423600","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372230000","value":"7","nid":"81447","platform":"-1"},{"timestamp":"1372413600","value":"1","nid":"118275","platform":"-1"},{"timestamp":"1373306400","value":"5","nid":"590502","platform":"-1"},{"timestamp":"1374264000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1371960000","value":"1","nid":"79568","platform":"-1"},{"timestamp":"1372924800","value":"1","nid":"82456","platform":"-1"},{"timestamp":"1373558400","value":"3","nid":"590502","platform":"-1"},{"timestamp":"1375092000","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1376280000","value":"1","nid":"701529","platform":"-1"},{"timestamp":"1370044800","value":"1","nid":"68566","platform":"-1"},{"timestamp":"1371380400","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1372183200","value":"3","nid":"81457","platform":"-1"},{"timestamp":"1372352400","value":"1","nid":"83613","platform":"-1"},{"timestamp":"1373194800","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1375689600","value":"1","nid":"687547","platform":"-1"},{"timestamp":"1371902400","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1372762800","value":"1","nid":"212931","platform":"-1"},{"timestamp":"1375977600","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1371322800","value":"2","nid":"59251","platform":"-1"},{"timestamp":"1372179600","value":"1","nid":"81457","platform":"-1"},{"timestamp":"1372345200","value":"2","nid":"83560","platform":"-1"},{"timestamp":"1373068800","value":"1","nid":"545517","platform":"-1"},{"timestamp":"1374163200","value":"1","nid":"607389","platform":"-1"},{"timestamp":"1375470000","value":"1","nid":"647526","platform":"-1"},{"timestamp":"1376460000","value":"1","nid":"705149","platform":"-1"},{"timestamp":"1370278800","value":"1","nid":"57508","platform":"-1"},{"timestamp":"1371765600","value":"2","nid":"79568","platform":"-1"},{"timestamp":"1372690800","value":"1","nid":"212147","platform":"-1"},{"timestamp":"1373382000","value":"9","nid":"590502","platform":"-1"},{"timestamp":"1374674400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1375819200","value":"1","nid":"697482","platform":"-1"},{"timestamp":"1371132000","value":"1","nid":"76647","platform":"-1"},{"timestamp":"1372143600","value":"1","nid":"81209","platform":"-1"},{"timestamp":"1372302000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1373036400","value":"1","nid":"545500","platform":"-1"},{"timestamp":"1373886000","value":"1","nid":"59251","platform":"-1"},{"timestamp":"1375380000","value":"1","nid":"646893","platform":"-1"},{"timestamp":"1376427600","value":"1","nid":"704735","platform":"-1"},{"timestamp":"1370260800","value":"3","nid":"68984","platform":"-1"},{"timestamp":"1372240800","value":"1","nid":"82162","platform":"-1"},{"timestamp":"1372428000","value":"1","nid":"154915","platform":"-1"},{"timestamp":"1373364000","value":"6","nid":"590502","platform":"-1"},{"timestamp":"1374606000","value":"1","nid":"610377","platform":"-1"}] }';
$json_object = json_decode($json);
var_dump($json_object);
Maybe it's your json_decode that's causing the issue.
You can pass an extra argument to json_decode that changes the returned value from an object (by default) to an array.
$json_array = json_decode($json, true);
See json_decode
Either there is a bug in your installation of PHP (you're using a release candidate, so that could be the issue) or there are some kind of illegal characters in the JSON file, which might not be posted here because stack overflow probably deletes weird characters.
Try a different version of PHP, or try going over the JSON code with a Hex Editor (I like HedFiend personally, but it only works on a mac).
Also try running json_decode() on partial snippets of the string instead of the entire thing.
You can go to this URL and have a nice look # your JSON :)
http://jsonviewer.stack.hu/

json_encode returns undefined with array of non-associative arrays

I try to encode data to JSON in PHP (Version 5.3.13) and send it to JavaScript.
My problem is:
When I encode an array of non-associative arrays, it returns undefined:
$arr = array(array(1, 2, 3));
echo json_encode($arr); // outputs nothing ("")
Can you help me?
Edit: my OS is FreeBSD 8.1-RELEASE
Edit: If it can help, I use this in MODX Evo web-site. I used this php-script as calling it form web-page, and all works fine. But then I create a snipet whih contains 1 line of code - include of this php-script. Now I call a web-page with nothing but this snippet in content.
Logically it is the same thing, but now it's not working.
Show all errors.
And use var_dump instead of echo.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$json = json_encode(array(array(1, 2, 3)));
var_dump($json);
Actually your script is working fine.
[[1,2,3]] //Output
My PHP Version 5.3.8 please would you mind to mention your php version.
May be your PHP version is less then 5.2

JSON from Javascript not decoding in PHP

I've been going bananas trying to get some data from Javascript on one page to post to a php file asynchronously. I'm not even attempting to do anything with the data, just a var_dump to spit back out from the ajax call. NULL over and over again.
I've checked the JSON with JSONLint and it validates just fine. I'm getting my JSON from JSON.stringify - Firebug tells me I'm getting the following:
{"items":[["sa1074","1060"],["sa1075","1061"]]}
I've tried php://input, as well as json_decode_nice from the PHP manual comments about the function, and I've tried using utf8_encode - is there something wrong with my JSON?
EDIT: Derpity dee probably should have planned this post a bit more haha. Here's my PHP (using a suggestion from PHP manual comments)
function json_decode_nice($json, $assoc = FALSE){
$json = str_replace(array("\n","\r"),"",$json);
$json = preg_replace('/([{,])(\s*)([^"]+?)\s*:/','$1"$3":',$json);
return json_decode($json,$assoc);
}
if (isset($_POST['build'])){
$kit = file_get_contents('php://input');
var_dump(json_decode_nice($kit));
}
And the JS used to create it:
var jsonKit = JSON.stringify(kit);
$.post("kits.php?", {"build" : jsonKit},
function(data) {
$("#kitItems").html(data);
});
Also: Our host is on PHP 5.2 - I found this out when I uploaded a perfectly good redbean class only to have it explode. Had to re-implement with legacy redbean. Our host is busted.
SOLVED: Thanks to all who commented. Didn't think to check $_POST to see what was coming in. Quotes were being escaped with slashes in the $_POST and json_decode was choking on it. Adding this line before decoding solved the problem. Also forgot to set true to return an associative array. Thanks!
$kit = str_replace('\\', '', $kit);
Without seeing code - I'm just guessing here ... are you using a true assoc variable in your json_decode()?
<?php json_decode($jsonString, true); ?>
That had me stumped on a decode for quite some time my first time trying to decode something,

Categories