We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我们直接进入主题,使用下面代码,返回一个json对象
@app.route("/") def hello_world(): data = {'message': 'test utf-8,中文!'} return data
用postman看返回 粗粗一看好像没啥问题
所有中文被写成/u开头的二次编码,虽然现在的json库都很强大,应该可以处理非UTF-8编码的内容。 但是这样总显得膈应。一定要打破砂锅问到底
普遍给我答案只要config里面配一下JSON_AS_ASCII=False就行。 看上去很容易解决! 但是实验下来就是没用!还是要找官档
The default app.json provider has equivalent attributes instead.
这句啥意思?可以通过app.json配置文件配置?
实验下来好像还是不行!
Flask的json编码不行,我自己编行不行?
@app.route("/") def hello_world(): data = {'message': 'test utf-8,中文!'} return json.dumps(data,ensure_ascii=False);
答案是不行!response被解析成了html/text。 硬来是不行的,还是要靠巧劲
最后有点陷入僵持了,报着试试的原则在Flask的网站里搜“ASCII”看看
找到相关项了
app = Flask(__name__) #app.config['JSON_AS_ASCII'] = False; #set = app.config.from_pyfile("config.py"); #print("load config" + str(set)); print(app.config); app.json.ensure_ascii=False; @app.route("/") def hello_world(): data = {'message': 'test utf-8,中文!'} #return json.dumps(data,ensure_ascii=False); #response = jsonify(data) return data #return "<p>中文你好!</p>"
最终解决方案!注释留着代表走过的弯路! 原来答案就在那句话里面
The default app.json provider has equivalent attributes instead. 只不过app.json不是配置文件,而是Flask的json属性!
原来我就是那只乌鸦!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
主要问题
我们直接进入主题,使用下面代码,返回一个json对象
用postman看返回
仔细一看发现问题了!response就不是用的UTF-8编码!粗粗一看好像没啥问题
疑问
所有中文被写成/u开头的二次编码,虽然现在的json库都很强大,应该可以处理非UTF-8编码的内容。
但是这样总显得膈应。一定要打破砂锅问到底
普遍给我答案只要config里面配一下JSON_AS_ASCII=False就行。
看上去很容易解决!
但是实验下来就是没用!还是要找官档
好像有点曙光,但是
这句啥意思?可以通过app.json配置文件配置?
实验下来好像还是不行!
Flask的json编码不行,我自己编行不行?
答案是不行!response被解析成了html/text。
硬来是不行的,还是要靠巧劲
最后有点陷入僵持了,报着试试的原则在Flask的网站里搜“ASCII”看看
找到相关项了
最终解决方案!注释留着代表走过的弯路!
原来答案就在那句话里面
原来我就是那只乌鸦!
参考链接
The text was updated successfully, but these errors were encountered: