问题描述
我有500,000行json文件正在尝试读取,我尝试了一些在线示例,例如mkyong和许多其他示例,但是这种格式对我来说是第一次遇到.谁能帮助我入门?
I have a 500,000 line json file I'm trying to read, I tried out a few online examples like mkyong's and many others, but this format is a first encounter for me. Can anyone help me to get started?
我正在使用json简单库.
I'm using json-simple library.
有人启发这个话题吗?我会很感激
Any enlighten on this topic? I'll be very grateful
{
"info": {
"category": "url",
"started": "2013-11-07 03:44:32",
"ended": "2013-11-07 03:46:55",
"version": "0.6",
"duration": 143,
"id": 37
},
"signatures": [],
"static": {},
"dropped": [
{
"yara": [],
"sha1": "6fd9eb6a42fd531988fba24137a2fe29ad992465",
"name": "tia[1].png",
"type": "PNG image data, 27 x 23, 8-bit/color RGB, non-interlaced",
"sha256": "75d6d26afb9506145d7f6472555855ef4305e0ef3e7cf4cb3d943c58123c7f74",
"crc32": "FDCAC92F",
"path": "/home/user/cuckoo/storage/analyses/37/files/2435944344/tia[1].png",
"ssdeep": null,
"size": 387,
"sha512": "b47ca17050ff4b6ddab848195c17b875454aafbec06d07bba126e553c9d32647f461adee9d1a75bbfffa08d6a8fc955429562794b123bebc9ec23dc89bdefcc5",
"md5": "ad07ee4cb98da073dda56ce7ceb88f5a"
}
]
}
回复
我目前不了解如何在[dropped]中获取数组,我做了一些简单的示例,但这对我来说是头一个.似乎有一个层次结构,但我不知道如何访问它
推荐答案
为什么不以 json-simple解码示例?如果是您担心的文件大小,则应使用"SAX"样式示例.这段代码将是一个很好的例子,说明如何不这样做.请参阅其他评论以获取更好的主意.
Why not start with the json-simple decoding examples? If it's the size of the file you're worried about, then you should use the 'SAX' style example. This code would be a good example of how not to do it. See the other comment for better ideas.
JSONObject data= (JSONObject)JSONValue.parse(new InputStreamReader(JsonSimpleEx.class.getResourceAsStream("/test.json")) );
JSONArray dropped = (JSONArray)data.get("dropped");
JSONObject first = (JSONObject)dropped.get(0);
System.out.println( first.get("crc32"));
这篇关于使用Java读取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!