Scrapyを使用して、いくつかのJSONデータを 'wotd-page-one.json'というファイルにスクラップしました。 JSONデータにはスペイン語が含まれており、アクセント付きの文字はUnicodeに変換されています。私はこのデータを読み込み、同じディレクトリ内のpythonスクリプトでusbaleにしたいと思います。このデータをリストにロードして、各JSONキーと値を個別に処理しようとしています。しかし、私はUnicodeとJSONを使った経験がないので、これを実現するのは苦労しています。誰も私がPythonリストを介してこれらのデータにアクセスできるようにする方法を見つけるのを助けてくれますか?理想的には、IDはdata [2] == "DEF" data [3] == "ユニコード文字をlatin-1に変換した文字列"とdata [4] == "SENTENCE" data [5] == JSONファイルと「ラテン-1に変換する任意のUnicode文字の文字列」Pythonでユニコードを含む廃止された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."}', ']']