Answer the question
In order to leave comments, you need to log in
How to decode json containing cyrillic?
Hello. I use sockets and send and receive packets through json serialization. But as soon as Cyrillic enters json, then complete gibberish is displayed on the screen in the form: \xd0\x9f\xd0\
How can I decode json so that all characters are displayed correctly?
# Отправка пакетов
def send_packages(conn, command):
json_data = json.dumps(str(command))
conn.send(bytes(json_data, 'utf-8'))
# Прием пакетов
def recieving_packages(conn):
json_data = ''
while True:
try:
data = conn.recv(8)
json_data += data.decode('utf-8')
return json.loads(json_data)
except ValueError:
continue
Answer the question
In order to leave comments, you need to log in
Strange use of json.dumps(). It takes a json object and returns a string. You are passing a string. Although, it may be necessary .
For json.dumps() there is a parameter ensure_ascii , which is responsible for encoding. Try passing ensure_ascii=False
There is an encoding parameter for json.loads()
import json
import codecs
json.load(codecs.open('sample.json', 'r', 'utf-8-sig'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question