J'ai supprimé certaines données JSON dans un fichier appelé 'wotd-page-one.json' en utilisant Scrapy. Les données JSON contiennent des mots espagnols et les lettres accentuées ont été converties en Unicode. Je voudrais charger ces données et les rendre usbale avec un script python dans le même répertoire. J'essaye de charger ces données dans une liste pour travailler chaque clé et valeur JSON individuellement. Cependant, j'ai du mal à y arriver puisque je n'ai pas beaucoup d'expérience avec Unicode et JSON. Quelqu'un pourrait-il m'aider s'il vous plaît à trouver un moyen de rendre ces données accessibles via une liste Python. Idéalement, je voudrais en faire quelque chose comme des données [2] == "DEF" données [3] == "chaîne avec tous caractères Unicode convertis en latin-1" et données [4] == "SENTENCE" données [5] == « chaîne avec tous les caractères unicode converti en latin-1 »Utilisation de données JSON mises au rebut contenant Unicode en Python
Python file:
data=[]
with open('wotd-page-one.json', encoding='utf-8') as f:
for line in f:
line = line.replace('\n', '')
data.append(line)
print(data)
JSON file:
[
{"TRANSLATION": "I don't like how that guy's whistling; it gives me the creeps.", "WORD": "silbar", "DEF": "to whistle", "SENTENCE": "No me gusta c\u00f3mo silba ese se\u00f1or; me da escalofr\u00edos."},
{"TRANSLATION": "\"Is somebody there?\" asked the boy in a startled voice.", "WORD": "sobresaltado", "DEF": "startled", "SENTENCE": "\"\u00bfHay alguien aqu\u00ed?\" pregunt\u00f3 el ni\u00f1o con voz sobresaltada."},
{"TRANSLATION": "Carla made a face at me when I asked her if she was scared.", "WORD": "la mueca", "DEF": "face", "SENTENCE": "Carla me hizo una mueca cuando le pregunt\u00e9 si ten\u00eda miedo."},
{"TRANSLATION": "The teacher tapped the board with the chalk.", "WORD": "golpetear", "DEF": "to tap", "SENTENCE": "El maestro golpete\u00f3 el pizarr\u00f3n con la tiza."}
]
Output:
['[',
'{"TRANSLATION": "I don\'t like how that guy\'s whistling; it gives me the creeps.", "WORD": "silbar", "DEF": "to whistle", "SENTENCE": "No me gusta c\\u00f3mo silba ese se\\u00f1or; me da escalofr\\u00edos."},', '
{"TRANSLATION": "\\"Is somebody there?\\" asked the boy in a startled voice.", "WORD": "sobresaltado", "DEF": "startled", "SENTENCE": "\\"\\u00bfHay alguien aqu\\u00ed?\\" pregunt\\u00f3 el ni\\u00f1o con voz sobresaltada."},', '
{"TRANSLATION": "Carla made a face at me when I asked her if she was scared.", "WORD": "la mueca", "DEF": "face", "SENTENCE": "Carla me hizo una mueca cuando le pregunt\\u00e9 si ten\\u00eda miedo."},', '
{"TRANSLATION": "The teacher tapped the board with the chalk.", "WORD": "golpetear", "DEF": "to tap", "SENTENCE": "El maestro golpete\\u00f3 el pizarr\\u00f3n con la tiza."}', ']']