【发布时间】:2018-06-11 10:59:14
【问题描述】:
我正在寻找this website,它使用插入和创建语句来获取 json 结构。 python中是否有任何相同的方法将具有插入和创建语句的sql查询转换为json格式。
示例: SQL查询:
/**
* Continents
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `continents`
-- ----------------------------
DROP TABLE IF EXISTS `continents`;
CREATE TABLE `continents` (
`code` char(2) NOT NULL COMMENT 'Continent code',
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- ----------------------------
-- Records of continents
-- ----------------------------
INSERT INTO `continents` VALUES ('AF', 'Africa');
INSERT INTO `continents` VALUES ('AN', 'Antarctica');
INSERT INTO `continents` VALUES ('AS', 'Asia');
INSERT INTO `continents` VALUES ('EU', 'Europe');
INSERT INTO `continents` VALUES ('NA', 'North America');
INSERT INTO `continents` VALUES ('OC', 'Oceania');
INSERT INTO `continents` VALUES ('SA', 'South America');
INSERT INTO `continents` VALUES ('??', NULL);
JSON 结构:
{
"continents": [
{
"code": "AF",
"name": "Africa"
},
{
"code": "AN",
"name": "Antarctica"
},
{
"code": "AS",
"name": "Asia"
},
{
"code": "EU",
"name": "Europe"
},
{
"code": "NA",
"name": "North America"
},
{
"code": "OC",
"name": "Oceania"
},
{
"code": "SA",
"name": "South America"
},
{
"code": "??",
"name": null
}
]
}
【问题讨论】:
-
不能从 SQL 中读取数据,然后将读取的数据转换成 JSON 吗?