import json
import pymysql
import MySQLdb
content = {
"stylers" : {
"color" : "#c4d7f5ff"
},
"elementType" : "geometry",
"featureType" : "water"
}
json_str = json.dumps(content)
print(json_str)
# json字符串不能直接写入到mysql中,需要进行转译
# django项目 MySQLdb.escape_string(json_str) 报错,AttributeError: module 'pymysql' has no attribute 'escape_string'
print(MySQLdb.escape_string(json_str))
# 换成pymysql ,下面可以正常转译
print(pymysql.converters.escape_string(json_str))
# {\"stylers\": {\"color\": \"#c4d7f5ff\"}, \"elementType\": \"geometry\", \"featureType\": \"water\"}
django项目 MySQLdb.escape_string(json_str) 报错,AttributeError: module ‘pymysql‘ has no attribute ‘escap
最新推荐文章于 2024-09-25 19:01:55 发布