Answer the question
In order to leave comments, you need to log in
How to solve encoding (cyrillic) problem when using SIMPLEJSON?
Hello.
I'm trying to work with JSON whose content has Cyrillic
code
#!/usr/bin/python
import simplejson as json
import os
os.environ["NLS_LANG"] = ".UTF8"
part_nums = ['RUN ВАСЯ RUN','CL05B103KB5NNNC','CC0402KRX5R8BB104']
# print(json.loads('Вася беги'.decode('utf8')))
def json_list(list):
lst = []
for pn in list:
d = {}
d['mpn']=pn
lst.append(d)
return json.dumps(lst)
print(json_list(part_nums))
print (json_list(part_nums).encode('UTF8').decode('UTF8'))
[{"mpn": "RUN \u0412\u0410\u0421\u042f RUN"}, {"mpn": "CL05B103KB5NNNC"}, {"mpn": "CC0402KRX5R8BB104"}]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question