我读过某个地方应该使用库salsify/jsonstreamingparser打开一个大json文件,但这给了我与json_decode相同的错误:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /data/www/default/database/vendor/salsify/json-streaming-parser/src/Listener/InMemoryListener.php on line 92
我必须在php中执行此操作,因为我正在使用没有python的免费托管。
基本上我想做的是下载一个大的json文件,将其解压缩并处理内容。我不知道为什么在php中我整天都无法做到,但是在python中我却在5分钟内做到了:
import os
import json
import urllib
import zipfile
json_file = 'AllSets-x.json'
zip_file = json_file + '.zip'
urllib.urlretrieve ("https://mtgjson.com/json/" + zip_file, zip_file)
dir_path = os.path.dirname(os.path.realpath(__file__))
zip_ref = zipfile.ZipFile(dir_path + "/" + zip_file, 'r')
zip_ref.extractall(dir_path)
zip_ref