Before anyone gives me crap about this being asked a billion times, please note that I've tried several of the answers in many a thread but none of them seemed to work properly for my problem.
import json
def parse(fn):
results = []
with open(fn) as f:
json_obj = json.loads(open(fn).read())
for r in json_obj["result"]:
print(r["name"])
parse("wine.json")
I'm basically just opening a json file and iterating it for some values. Obviously, whenever I read a value with some unicode in it I get this error.
Traceback (most recent call last):
File "json_test.py", line 9, in <module>
parse("wine.json")
File "json_test.py", line 7, in parse
print(r["name"])
File "C:Python34libencodingscp850.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character 'u201c' in position
15: character maps to <undefined>
As people said in other threads I've tried to encode it and whatnot, but then I get a similar error, no matter how I encode and/or decode it. Please help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…