I’m creating a JSON arrary in Jquery and then sending it to php. In php I decode it but I get an error message. Below is an echo of the array that arrives in php and the error message. Note: I have only passed one item (to keep it smaller but in the further there would be more items in the array:

This is the current PHP code:
print_r($_POST['cropData']);
$cropData = json_decode($_POST['cropData']);
print_r($cropData);
Also here is the jquery to generate the json array:
jsonArray[thumbNum] = [{'src':val.attr('src')},
{'width':val.width()},
{'height':val.height()},
{'dataCX':val.attr('data-cx')},
{'dataCY':val.attr('data-cy')},
{'dataCW':val.attr('data-cw')},
{'dataCH':val.attr('data-ch')}
]
thumbNum++;
}
$.post('scripts/php/join_processing.php', {
'cropJoin': '1',
'cropData': jsonArray},
function(data) {
Any advise on what I’m doing wrong here? I’m I sending an badly formed JSON array or not encoding it correctly?
thx
Because the data-parameter of jQuery.post() is “intelligent guess”,
if you pass a JSON-string or a JS-object as data-parameter in jQuery.post(), it already posts it as an HTTP POST-array instead of a single json-string.
So, what you’re receiving in php is already a usable array, so there’s no need to decode it.
Btw; you could’ve easily seen this since you print_r the POST-variable and it obviously prints it as an array instead of a string.