Scrapy를 사용하여 일부 JSON 데이터를 'wotd-page-one.json'이라는 파일로 스크랩했습니다. JSON 데이터에는 스페인어 단어가 포함되어 있으며 악센트 부호가있는 문자는 유니 코드로 변환되었습니다. 이 데이터를로드하고 동일한 디렉토리 내의 python 스크립트로 usbale을 만들고 싶습니다. 각 JSON 키와 값을 개별적으로 작업하기 위해이 데이터를 목록에로드하려고합니다. 그러나 유니 코드와 JSON을 사용하여 많은 경험을 한 경험이 없기 때문에 이런 일이 발생하는 데 어려움을 겪고 있습니다. 아무도 파이썬 목록을 통해 이러한 데이터에 액세스 할 수있는 방법을 찾도록 도와 줄 수 있습니까? 이상적으로, ID는 data [2] == "DEF"data [3] == "유니 코드 문자가 latin-1로 변환 된 문자열"과 data [4] == "SENTENCE"data [5] 에서 == JSON 파일로파이썬에서 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."}', ']']