本文整理了Java中javax.json.stream.JsonParser.hasNext()
方法的一些代码示例,展示了JsonParser.hasNext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonParser.hasNext()
方法的具体详情如下:
包路径:javax.json.stream.JsonParser
类名称:JsonParser
方法名:hasNext
[英]Returns true if there are more parsing states. This method returns false if the parser reaches the end of the JSON text.
[中]如果存在更多解析状态,则返回true。如果解析器到达JSON文本的末尾,则此方法返回false。
代码示例来源:origin: org.eclipse/yasson
@Override
public boolean hasNext() {
return jsonParser.hasNext();
}
代码示例来源:origin: org.apache.johnzon/johnzon-core
@Override
public boolean hasNext() {
return jsonParser.hasNext();
}
代码示例来源:origin: apache/johnzon
@Override
public boolean hasNext() {
return jsonParser.hasNext();
}
代码示例来源:origin: org.ovirt.engine.api/metamodel-runtime
/**
* Skips the current JSON object or array.
*/
public void skip() {
int depth = 1;
while (parser.hasNext()) {
switch (parser.next()) {
case START_ARRAY:
case START_OBJECT:
depth++;
break;
case END_ARRAY:
case END_OBJECT:
depth--;
if (depth == 0) {
return;
}
break;
}
}
}
代码示例来源:origin: stackoverflow.com
Map<String, String> values = new HashMap<>();
String keyName = null;
JsonParser jsonParser = Json.createParser(new StringReader(json));
while (jsonParser.hasNext())
{
JsonParser.Event event = jsonParser.next();
if (JsonParser.Event.KEY_NAME.equals(event))
{
keyName = jsonParser.getString();
}
else if (JsonParser.Event.VALUE_STRING.equals(event))
{
values.put(keyName, jsonParser.getString());
}
}
代码示例来源:origin: stackoverflow.com
String jsonString="";
JsonParser jParser= Json.createParser(new ByteArrayInputStream(jsonString.getBytes()));
while(jParser.hasNext()){
if(jParser.next()==Event.KEY_NAME){
if(jParser.getString().equals("viewCount")){
jParser.next();
System.out.println(jParser.getString());
}
}
}
代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.core
private void doParsing(JsonParser parser) throws SAXException, IOException {
JsonStructureBuilder builder = null;
while (parser.hasNext()) {
builder = parseEvent(parser);
}
assert builder != null;
JsonStructure jsonStructure = builder.build();
structureReader.parseRoot(jsonStructure);
}
代码示例来源:origin: com.haulmont.thirdparty/eclipselink
private void doParsing(JsonParser parser) throws SAXException, IOException {
JsonStructureBuilder builder = null;
while (parser.hasNext()) {
builder = parseEvent(parser);
}
assert builder != null;
JsonStructure jsonStructure = builder.build();
structureReader.parseRoot(jsonStructure);
}
代码示例来源:origin: webex/spark-java-sdk
private void scrollToItemsArray(JsonParser parser) {
JsonParser.Event event;
while (parser.hasNext()) {
event = parser.next();
if (event == JsonParser.Event.KEY_NAME && parser.getString().equals("items")) {
break;
}
}
event = parser.next();
if (event != JsonParser.Event.START_ARRAY) {
throw new SparkException("bad json");
}
}
代码示例来源:origin: dsukhoroslov/bagri
/**
*
* @param parser the JSON streaming parser
* @return the list of parsed XDM data elements
* @throws BagriException in case of any parsing error
*/
public ParseResults parse(JsonParser parser) throws BagriException {
ParserContext ctx = initContext();
while (parser.hasNext()) {
processEvent(ctx, parser);
}
return ctx.getParseResults();
}
代码示例来源:origin: agoncal/agoncal-book-javaee7
public String parsePurchaseOrderAndReturnEmail() throws FileNotFoundException {
String email = null;
JsonParser parser = Json.createParser(new FileReader("src/main/resources/order.json"));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
while (parser.hasNext() && !(event.equals(JsonParser.Event.KEY_NAME) && parser.getString().matches("email"))) {
event = parser.next();
}
if (event.equals(JsonParser.Event.KEY_NAME) && parser.getString().matches("email")) {
parser.next();
email = parser.getString();
}
}
return email;
}
}
代码示例来源:origin: radcortez/wow-auctions
@Override
public Object readItem() throws Exception {
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
Auction auction = new Auction();
switch (event) {
case KEY_NAME:
if (readAuctionItem(auction)) {
return auction;
}
break;
}
}
return null;
}
代码示例来源:origin: beckchr/staxon
private Event peekEvent() throws IOException {
if (peekEvent == null) {
try {
if (parser.hasNext()) {
peekEvent = parser.next();
}
} catch (JsonException e) {
if (e.getCause() instanceof IOException) {
throw (IOException) e.getCause();
} else {
throw e;
}
}
}
return peekEvent;
}
代码示例来源:origin: javaee/javaee7-samples
public static void main(String... args) throws Exception {
URL url = new URL("https://graph.facebook.com/search?q=java&type=post");
try (InputStream is = url.openStream();
JsonParser parser = Json.createParser(is)) {
while (parser.hasNext()) {
Event event = parser.next();
if (event == Event.KEY_NAME) {
switch (parser.getString()) {
case "name":
parser.next();
System.out.println("----> " + parser.getString());
break;
case "message":
parser.next();
System.out.println("----> " + parser.getString());
System.out.println("**************");
break;
}
}
}
}
}
}
代码示例来源:origin: owlike/genson
@Override
public JsonObject readObject() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_OBJECT == evt) {
return read(builderFactory.createObjectBuilder()).build();
} else throw new JsonException("Expected " + START_OBJECT + " but got " + evt);
}
throw new JsonException("Empty stream");
}
代码示例来源:origin: com.owlike/genson
@Override
public JsonObject readObject() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_OBJECT == evt) {
return read(builderFactory.createObjectBuilder()).build();
} else throw new JsonException("Expected " + START_OBJECT + " but got " + evt);
}
throw new JsonException("Empty stream");
}
代码示例来源:origin: owlike/genson
@Override
public JsonArray readArray() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_ARRAY == evt) {
return read(builderFactory.createArrayBuilder()).build();
} else throw new JsonException("Expected " + START_ARRAY + " but got " + evt);
}
throw new JsonException("Empty stream");
}
代码示例来源:origin: com.owlike/genson
@Override
public JsonStructure read() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_OBJECT == evt) {
return read(builderFactory.createObjectBuilder()).build();
} else if (START_ARRAY == evt) {
return read(builderFactory.createArrayBuilder()).build();
} else throw new JsonException("Expected START_OBJECT or START_ARRAY but got " + evt);
}
throw new JsonException("Empty stream");
}
代码示例来源:origin: owlike/genson
@Override
public JsonStructure read() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_OBJECT == evt) {
return read(builderFactory.createObjectBuilder()).build();
} else if (START_ARRAY == evt) {
return read(builderFactory.createArrayBuilder()).build();
} else throw new JsonException("Expected START_OBJECT or START_ARRAY but got " + evt);
}
throw new JsonException("Empty stream");
}
代码示例来源:origin: com.owlike/genson
@Override
public JsonArray readArray() {
checkNotReadedAndRead();
if (parser.hasNext()) {
Event evt = parser.next();
if (START_ARRAY == evt) {
return read(builderFactory.createArrayBuilder()).build();
} else throw new JsonException("Expected " + START_ARRAY + " but got " + evt);
}
throw new JsonException("Empty stream");
}
内容来源于网络,如有侵权,请联系作者删除!