我有一個包含至少30 000個字符的json文件。它可以在這裏找到:從具有多個字典的json文件讀取時出錯
http://openxcplatform.com.s3.amazonaws.com/traces/nyc/downtown-west.json
我已經通過互聯網鞭打,發現這給我帶來了最接近我需要什麼,我需要逐個通過JSON文件讀取,輸入http://stardict.sourceforge.net/Dictionaries.php下載爲一個實際的字典到列表中:
with open("test.json") as data_file:
for x in data_file:
json.dumps(it.append(ast.literal_eval(x)))
我測試了這個代碼,它的工作大部分。我第一個2000個元素測試,但是,一旦我測試整個文件,我收到此錯誤:
File "converter.py", line 58, in <module>
if __name__ == "__main__": main()
File "converter.py", line 34, in main
json.dumps(it.append(ast.literal_eval(x)))
File "/usr/lib/python2.7/ast.py", line 80, in literal_eval
return _convert(node_or_string)
File "/usr/lib/python2.7/ast.py", line 63, in _convert
in zip(node.keys, node.values))
File "/usr/lib/python2.7/ast.py", line 62, in <genexpr>
return dict((_convert(k), _convert(v)) for k, v
File "/usr/lib/python2.7/ast.py", line 79, in _convert
raise ValueError('malformed string')
ValueError: malformed string
人知道爲什麼會發生?