简体   繁体   English

将嵌套的json存储到节点中的mysql数据库中

[英]Storing nested json into mysql db in node

I want to store the following data into a mysql db. 我想将以下数据存储到mysql数据库中。

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; Choices是javascript对象的var choices; and tags is var tags; 标签是var标签; I want to store in just 3 columns of a mysql db. 我只想存储在mysql数据库的3列中。

I have tried JSON.stringify(choices) to no avail. 我尝试了JSON.stringify(choices)无济于事。

The choices array and tags object are within the data object, so get them like this: choices数组和标签对象位于数据对象内,因此请按以下方式获取它们:

var choices = JSON.stringify(data.choices);
var tags = JSON.stringify(data.tags);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM