我正在尝试解析从对 Facebook 的请求中提供的提要。但是,我的解析器跳过了很多信息。下面是代码的一部分,一个正在解析的内容以及 if 语句中打印的内容的示例。例如,从未找到“消息”。想法?
List<FacebookItem> list = new ArrayList<FacebookItem>();
try {
if (jFactory == null)
jFactory = new JsonFactory();
jParser = jFactory.createJsonParser(json);
FacebookItem o = null;
while (jParser.nextToken() != null) {
if ("type".equals(jParser.getCurrentName())) {
jParser.nextToken();
o = new FacebookItem();
o.setType(jParser.getText());
System.out.println("Found type: " + jParser.getText());
}
if ("from".equals(jParser.getCurrentName()))
while (!"name".equals(jParser.getCurrentName())) {
jParser.nextToken();
}
jParser.nextToken();
o.getUser().setUserName(jParser.getText());
System.out.println("Found name: " + jParser.getText());
}
if ("message".equals(jParser.getCurrentName())) {
jParser.nextToken();
o.setText(jParser.getText());
System.out.println("Found message: " + jParser.getText());
}
if ("created_time".equals(jParser.getCurrentName())) {
jParser.nextToken();
o.setTimestamp(jParser.getText());
System.out.println("Found created_time: " + jParser.getText());
list.add(o);
}
}
jParser.close();
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
{"data":[{"type":"photo","link":"http://www.facebook.com/photo.php?fbid=10151331660204305&set=a.299455459304.180838.197394889304&type=1&relevant_count=1"," from":{"name":"FC Barcelona","category":"职业运动队","id":"197394889304"},"message":"普约尔面临八周裁员 http://bit.ly/ QXhOFE\r\n\r\nPuyol, vuit setmanes de baixa http://bit.ly/T1enma\r\n\r\nPuyol, ocho semanas de baja http://bit.ly/T0eaj8","图片" :"http://photos-g.ak.fbcdn.net/hphotos-ak-snc6/246623_10151331660204305_75156416_s.jpg","created_time":"2012-10-03T17:40:06+0000","id":" 197394889304_10151331937599305"},{"type":"checkin",“链接”:“http://www.facebook.com/pages/Hubben-21/249474758405147”,“来自”:{“名称”:“Andreas Rol\u00e9n”,“id”:“575703056”}, message":"En timme in i turneringen och redan chipleader","picture":"http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/y5/r/j258ei8TIHu.png", "name":"Hubben 2.1","created_time":"2012-10-03T17:24:19+0000","id":"575703056_10151181582028057"},{"type":"photo","link":" http://www.facebook.com/photo.php?fbid=10151445544542786&set=at.10151445533587786.588547.694032785.688088336&type=1&relevant_count=1","from":{"name":"Jens Wilhelmsson","id":"688088336 "},"图片":"http://photos-h.ak.fbcdn.net/hphotos-ak-prn1/72091_10151445544542786_676020840_s.jpg","created_time":"2012-10-03T17:21:40+0000","id" :"688088336_10151111148358337"},{"type":"link","from":{"name":"Eric Lindqvist","id":"648057222"},"created_time":"2012-10-03T17:20 :52+0000","id":"648057222_10151249963167223"}created_time":"2012-10-03T17:20:52+0000","id":"648057222_10151249963167223"}created_time":"2012-10-03T17:20:52+0000","id":"648057222_10151249963167223"}
Found type: photo
Found name: FC Barcelona
Found name: Andreas Rolén
Found name: Hubben 2.1
Found created_time: 2012-10-03T17:24:19+0000
Found type: photo
Found name: Jens Wilhelmsson
Found name: Eric Lindqvist