I am new to JSON,ofr a project of my own I need to send array of objects to the server. Basically, I have a Question object, which has a couple of properties, like question, optionA, optionB etc. I have an array of Question objects.
example:
qArray = new Array();
qArray.push(new Question("where do you live?", "England", "ıtaly", "Usa");
I am adding a lot of questions objects to this array and in the end, I need to send this array to the server, like this:
$.post("backend-stuff/aj-save-test.php", { testName : $("#testName").val().toString(), 'questions' : JSON.stringify(qArray)}, function(result){
alert(result);
});
}
In PHP, I use this,
$questions = json_decode($_POST["questions"]);
$testName = $_POST["testName"];
Problem is that I cant read data, either I am sending it in the wrong way or whats wrong is on the php side.
Thank you for answers, I checked Google before sending the question, so please forgive me if this is so easy but for me its not so.
要将stdClassObject转换为数组,请检出get_object_vars() 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.