Last active
January 28, 2017 10:29
-
-
Save mylamour/eb6180664142810d58041c8f182e5432 to your computer and use it in GitHub Desktop.
conert single line json with unicode to normal, 解决读取人名乱码问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#这个是真奇怪,从pg里拿到的数据,怎么转换也不行,最后只能用这种办法修改的, | |
# s.decode("UTF-8").encode("GBK") 之前爬虫时可以用,但是现在这个场景不适合。 | |
import json | |
with open('/home/ubuntu/origin/musicgroup.json') as origin, open('/home/ubuntu/json/musicgroup.json','w') as dest: | |
for i in origin.readlines(): | |
t = json.loads(i) | |
dest.write(json.dumps(t, ensure_ascii=False).encode('utf8') + '\n') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment