将嵌套的json存储到节点中的mysql数据库中 [英] Storing nested json into mysql db in node

查看:507
本文介绍了将嵌套的json存储到节点中的mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将以下数据存储到mysql数据库中.

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"
    }
  };

选择是javascript对象的var选项;标签是var标签; 我只想将其存储在mysql数据库的3列中.

Choices is a javascript object var choices; and tags is var tags; I want to store in just 3 columns of a mysql db.

我尝试JSON.stringify(choices)无济于事.

I have tried JSON.stringify(choices) to no avail.

推荐答案

choices数组和标签对象位于数据对象中,因此请按以下方式获取它们:

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);

这篇关于将嵌套的json存储到节点中的mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆