这是我的 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();