文章内容
2018/2/7 14:12:45,作 者: 黄兵
TypeError: Object of type 'CH_REGION' is not JSON serializable
最近在写代码的时候,老是提示:
Object of type 'CH_REGION' is not JSON serializable
代码内容如下:
@auth.route('/country', methods=['GET', 'POST'])
def country():
ID = request.values.get('country', 0)
city = CH_REGION.query.filter_by(PARENT_ID=ID).all()
return json.dumps(city)出现这个错误的原因是:CH_REGION无法序列化。
解决方案:
@auth.route('/country', methods=['GET', 'POST'])
def country():
ID = request.values.get('country', 0)
city = CH_REGION.query.filter_by(PARENT_ID=ID).all()
for item in city:
data = {'ID': item.ID,'REGION_NAME':item.REGION_NAME}
return json.dumps(data)参考资料:
TypeError: Object of type 'Tag' is not JSON serializable
Convert a list to json objects
黄兵个人博客原创
转载请注明出处:黄兵个人博客 - TypeError: Object of type 'CH_REGION' is not JSON serializable
评论列表