This是我的JSON来源。我们可以跳过retweeted_status
令牌并移至下一个contributors
令牌(而不是retweeted_status
令牌中的令牌)。
目前,以下代码进入retweeted_status
对象并解析其中的每一个:
jp = jsonF.createJsonParser(strLine);
if (jp.nextToken() != JsonToken.START_OBJECT) {
throw new IOException("Expected data to start with an Object");
}
TwitterEntry result = new TwitterEntry();
// Iterate over object fields:
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jp.getCurrentName();
// Let's move to value
jp.nextToken();
if (fieldName.equals("id")) {
result.setId(jp.getLongValue());
} else if (fieldName.equals("text")) {
result.setText(jp.getText());
} else if (fieldName.equals("fromUserId")) {
result.setFromUserId(jp.getIntValue());
} else if (fieldName.equals("toUserId")) {
result.setToUserId(jp.getIntValue());
} else if (fieldName.equals("languageCode")) {
result.setLanguageCode(jp.getText());
} else { // ignore, or signal error?
//Ignoring unrecognized fields
//throw new IOException("Unrecognized field '"+fieldName+"'");
}
}
jp.close();
答案 0 :(得分:2)
您应该能够在else语句中使用jp.skipChildren()。
即
...
else {
jp.nextToken(); // go to value token
jp.skipChildren(); // skip if object or array
}
...