我使用Scrapy將一些JSON數據報廢爲名爲「wotd-page-one.json」的文件。 JSON數據包含一些西班牙語單詞,重音字母被轉換爲Unicode。我想加載這些數據並在同一個目錄下使用python腳本進行製作。我正嘗試將這些數據加載到列表中以分別處理每個JSON密鑰和值。但是,由於我沒有使用Unicode和JSON的豐富經驗,所以我很難做到這一點。任何人都可以請幫助我找到一種方法,使這些數據可以通過Python列表訪問。理想情況下,我想使它像數據[2] ==「DEF」數據[3] ==「字符串與任何Unicode字符轉換爲拉丁-1」和數據[4] ==「SENTENCE」數據[5] ==「字符串與任何Unicode字符轉換爲Latin-1的」在Python中使用包含Unicode的報廢的JSON數據
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."}', ']']