Java Reference
In-Depth Information
String id = reader . getText ();
isItemID = false
false ;
iif ( addItemId ( id )) {
return
return ;
}
}
break
break ;
default
default :
break
break ;
}
}
The parser returns a series of tokens. In the example most tokens are just discarded. When a
start token is found, the code checks to see if the token is an item ID. If it is, then the next
character token will be the ID the application wants to save. The ID is saved via the ad-
dItemId() method, which returns true if the desired number of IDs have been stored. When
that happens, the loop can just return and not process the remaining data in the input stream.
Conceptually, the JSON parser works exactly the same way; only some of the API calls have
changed:
while
while ( parser . hasNext ()) {
Event event = parser . next ();
switch
switch ( event ) {
case
case KEY_NAME:
String s = parser . getString ();
iif ( ITEM_ID . equals ( s )) {
isItemID = true
true ;
}
break
break ;
case
case VALUE_STRING:
iif ( isItemID ) {
iif ( addItemId ( parser . getString ())) {
return
return ;
}
isItemID = false
false ;
}
continue
continue ;
default
default :
continue
continue ;
}
}
Search WWH ::




Custom Search