Created
February 18, 2019 07:26
-
-
Save kamontat/bfd00a3a3a4f2d64cb01f59af16b73fc to your computer and use it in GitHub Desktop.
convert facebook information encode to correct one (only appear when export as JSON)
This file contains hidden or 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
import json | |
def parse_obj(obj): | |
for key in obj: | |
if type(obj[key]) is str: | |
obj[key] = obj[key].encode('latin_1').decode('utf-8') | |
elif type(obj[key]) is list: | |
obj[key] = list(map(lambda x: x if type(x) != str else x.encode('latin_1').decode('utf-8'), obj[key])) | |
pass | |
return obj | |
filename = '' | |
# File | |
with open(filename) as f: | |
text = json.load(f, object_hook=parse_obj) | |
print(text) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment