Answer the question
In order to leave comments, you need to log in
How to teach JSON to understand Cyrillic using Python?
When I pull data from the database and convert it to JSON to send it to the frontend, I get incorrect data conversion to JSON due to the presence of Cyrillic. How can I teach JSON to understand Cyrillic so that the information in the second print looks the same as in the first one?
@app.route('/student', methods=['POST'])
def get_loginn():
new_one = request.json
s = json.dumps(new_one)
x = json.loads(s, object_hook=lambda d: SimpleNamespace(**d))
with sq.connect("diary.db") as con:
cur = con.cursor()
cur.execute("SELECT * FROM student")
for result in cur:
if result[0] == x.id_user:
print(result)
f = json.dumps(result)
print(f)
return jsonify(f)
Answer the question
In order to leave comments, you need to log in
Why are you creating a json string before calling jsonify? Transfer your data immediately jsonify(result)
And so that there are no problems with the Cyrillic alphabet, write
app.config['JSON_AS_ASCII'] = False
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question