使用GSON解析带有未命名字段的JSON数组

时间:2014-09-19 16:37:12

标签: java json parsing

所以我想将flightradar24.com数据解析为Java程序。数据似乎是JSON-ish,因此我试图使用GSONs JSonParser来读取它。

以下是我尝试解析的内容的简短摘录(您可以完整地看到它,例如在http://arn.data.fr24.com/zones/italy_all.js?callback=pd_callback中):

pd_callback({"45da286":["4CAAB6",43.5609,12.6837,211,34975,420,"7311","F-LIBP2","B772","EI-ISA",1411143824,"NRT","FCO","AZ785",0,0,"AZA785",0],
"45dae4b":["7809B9",47.5892,15.8256,204,36000,442,"7303","F-LKTB2","A332","B-5921",1411143824,"PVG","FCO","MU787",0,0,"CES787",0],
"45dae73":["76CEF7",47.6238,17.2440,291,36000,428,"0342","F-LKTB1","B77W","9V-SWW",1411143826,"SIN","LHR","SQ318",0,0,"SIA318",0],
"45db3e2":["71BC61",46.0211,10.0549,242,22800,344,"7313","F-LIPE1","B744","HL7461",1411143824,"ICN","MXP","KE927",0,-2176,"KAL927",0],
"full_count":10394,"version":4});

上面示例中的每一行都类似于当时某个航班的数据,包括id,lat,lon等。我删除了pd_callback(...);只是为了尝试它,我删除了"" full_count":10394,"版本":4"同样。当我尝试将此字符串解析为可迭代的JSON对象数组时,例如,像这样:

com.google.gson.JsonParser jsonParser = new JsonParser();
com.google.gson.JsonArray jsa = jsonParser.parse(line).getAsJsonArray();

我总是得到解析错误。我认为其中一个问题是没有给出字段名称,语法可能是错误的,但实际上这就是flightradar读取数据的方式。最后,我只希望能够遍历每个航班并将每个属性作为基元读取,然后将其提供给我自己的对象。

任何人都知道问题在哪里或如何方便地解析这类数据?任何评论赞赏。

0 个答案:

没有答案