我有以下格式的 JSON 数据
{"createdAt": "2013-06-02T00:00:00-08:00", "sessionId": "4982b321-1a24-4295-9fce-c106362218ca", "user": 86157463, "type": "Play", "payload": {"itemId": "15869e7", "marker": 604}, "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1", "refId": "b7b4d324", "auth": "38746efc:a1681031"}
{"createdAt": "2013-06-02T00:00:00-08:00", "type": "Login", "user": 32850778, "sessionId": "a0e125a3-4e52-42a7-b35f-c9382a8a0e9b", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.5; rv:7.0.1) Gecko/20100101 Firefox/7.0.1", "refId": "dd4d56c5", "auth": "69646ac4:a7a75b53"}
{"createdAt": "2013-06-02T00:00:24-08:00", "sessionId": "db7d0113-b688-4737-b3b9-5da92e3de23a", "user": 95035757, "type": "Recommendations", "payload": {"recommendedItems": ["10611", "9722e23", "31396", "28828", "20662", "17342", "21070", "28415", "18273", "27930", "35266", "28895", "11108", "12121", "16045", "12203", "11423", "13363e27", "21304", "18724e1", "38111e66", "9232", "36851e45", "31672", "14502"]}, "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19", "refId": "e94bc09f", "auth": "699d7b63:cec0d4e1"}
如您所见,每条记录都有不同顺序的不同字段。当我使用 GSON 解析上述代码时,我只得到第一条记录的结果。我正在使用以下代码
BufferedReader br = new BufferedReader( new FileReader("C:/Users/inhmadala/Desktop/SampleCCP.json"));
Gson gson = new GsonBuilder().create();
JsonReader reader = new JsonReader(new StringReader(br.readLine()));
reader.setLenient(true);
//convert the json string back to object
//JsonReader.setLenient(true);
DataObject obj = gson.fromJson(reader, DataObject.class);
有人可以告诉我这里出了什么问题。