以下是崩溃我的Julia内核.有没有更好的方法来读取和解析大型(> 400 MB)JSON文件?
using JSON
data = JSON.parsefile("file.json")
Run Code Online (Sandbox Code Playgroud)
除非投入一些精力来制作更智能的 JSON 解析器,否则以下内容可能会起作用:很有可能file.json有很多行。在这种情况下,读取文件并逐行或逐块解析大的重复 JSON 部分(以获得正确的块长度)可以解决问题。对此进行编码的一种可能方法是:
using JSON
f = open("file.json","r")
discard_lines = 12 # lines up to repetitive part
important_chunks = 1000 # number of data items
chunk_length = 2 # each data item has a 2-line JSON chunk
for i=1:discard_lines
l = readline(f)
end
for i=1:important_chunks
chunk = join([readline(f) for j=1:chunk_length])
push!(thedata,JSON.parse(chunk))
end
close(f)
# use thedata
Run Code Online (Sandbox Code Playgroud)
这很可能是解决您问题的临时权宜之计。检查一下file.json就知道了。
| 归档时间: |
|
| 查看次数: |
916 次 |
| 最近记录: |