I want to store the following data into a mysql db.
var data = {
type: "binary",
choices: [
{
choice: "No",
answers: 18
},
{
choice: "Yes",
answers: 11
}
],
tags: {
2851: "road",
8685: "had",
10978: "heard"
}
};
Choices is a javascript object var choices; and tags is var tags;
I want to store in just 3 columns of a mysql db.
I have tried JSON.stringify(choices) to no avail.
解决方案
The choices array and tags object are within the data object, so get them like this:
var choices = JSON.stringify(data.choices);
var tags = JSON.stringify(data.tags);