Skip to content

Instantly share code, notes, and snippets.

@mylamour
Last active January 28, 2017 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mylamour/eb6180664142810d58041c8f182e5432 to your computer and use it in GitHub Desktop.
Save mylamour/eb6180664142810d58041c8f182e5432 to your computer and use it in GitHub Desktop.
conert single line json with unicode to normal, 解决读取人名乱码问题
#这个是真奇怪,从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