-3
I’m trying to import the Friends.json file from Facebook, but I’m having trouble accentuating it. Friends.json file is something like:
{
"friends": [
{
"name": "Marco Aur\u00c3\u00a9lio Ferreira",
"timestamp": 1617453534
},
{
"name": "Tha\u00c3\u00ads Everton D. Soares Papaleo",
"timestamp": 1617420287
}
]
}
The code I’m using is:
# encoding in UTF-8
import json
with open("friends.json", "r", encoding='UTF-8') as read_file:
data = json.load(read_file)
data = (data['friends'])
for n in data:
nome = n['name']
print(nome)
However the return is as follows:
Marco Aurélio Ferreira
ThaÃs Everton D. Soares Papaleo
Honestly I’ve tried everything, but I can’t fix the accent. Someone has some light?
tried
latin-1
?– Lucas
Yes. I also tried the codecs library, codecs.open function, but also did not give.
– Otavio
The fact of leaving different from what you expect seems to be a problem at print time (the place where you are reading the string, whether console, IDE or something like that is not in UTF-8), which does not mean that Py is wrong. If you can get [Edit] to post and provide a [mcve], it would help a lot (Dit: and put where you’re using the output, if you’re going to use it on the console, that OS etc - locks are not intended to be definitive and are not punishment, so we always invite you to edit the posts - it’s not personal, and it doesn’t mean you’re not welcome, quite the contrary).
– Bacco
Not the IDE’s problem. But the Kaique solution worked. Plus my post was a Minimal, Complete and Verifiable example.
– Otavio