本文整理了Java中com.google.api.client.json.JsonParser.nextToken()
方法的一些代码示例,展示了JsonParser.nextToken()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonParser.nextToken()
方法的具体详情如下:
包路径:com.google.api.client.json.JsonParser
类名称:JsonParser
方法名:nextToken
暂无
代码示例来源:origin: com.google.http-client/google-http-client-test
public final void testGson() throws Exception {
byte[] asciiJson = Charsets.UTF_8.encode("{ \"foo\": 123 }").array();
JsonParser jp =
newFactory().createJsonParser(new ByteArrayInputStream(asciiJson), Charsets.UTF_8);
assertEquals(com.google.api.client.json.JsonToken.START_OBJECT, jp.nextToken());
assertEquals(com.google.api.client.json.JsonToken.FIELD_NAME, jp.nextToken());
assertEquals(com.google.api.client.json.JsonToken.VALUE_NUMBER_INT, jp.nextToken());
assertEquals(123, jp.getIntValue());
assertEquals(com.google.api.client.json.JsonToken.END_OBJECT, jp.nextToken());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_partialEmpty() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
parser = factory.createJsonParser(EMPTY_OBJECT);
parser.nextToken();
parser.nextToken();
// current token is now end_object
@SuppressWarnings("unchecked")
HashMap<String, Object> result = parser.parseAndClose(HashMap.class);
assertEquals(EMPTY_OBJECT, factory.toString(result));
// check types and values
assertTrue(result.isEmpty());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParseFeed() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
parser.nextToken();
Feed feed = parser.parseAndClose(Feed.class);
Iterator<Entry> iterator = feed.entries.iterator();
assertEquals("foo", iterator.next().title);
assertEquals("bar", iterator.next().title);
assertFalse(iterator.hasNext());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParse_emptyMap() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
@SuppressWarnings("unchecked")
HashMap<String, Object> map = parser.parseAndClose(HashMap.class);
assertTrue(map.isEmpty());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
@SuppressWarnings("unchecked")
public void testParseEntryAsMap() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
HashMap<String, Object> map = parser.parseAndClose(HashMap.class);
assertEquals("foo", map.remove("title"));
assertTrue(map.isEmpty());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_partialEntry() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
parser = factory.createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.nextToken();
// current token is now field_name
Entry result = parser.parseAndClose(Entry.class);
assertEquals(JSON_ENTRY, factory.toString(result));
// check types and values
assertEquals("foo", result.title);
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParse() throws Exception {
JsonParser parser = newFactory().createJsonParser(CONTAINED_MAP);
parser.nextToken();
A a = parser.parse(A.class);
assertEquals(ImmutableMap.of("title", "foo"), a.map);
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_collectionType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
parser = factory.createJsonParser(COLLECTION_TYPE);
parser.nextToken();
CollectionOfCollectionType result = parser.parse(CollectionOfCollectionType.class);
assertEquals(COLLECTION_TYPE, factory.toString(result));
// check that it is actually a linked list
LinkedList<LinkedList<String>> arr = result.arr;
LinkedList<String> linkedlist = arr.get(0);
assertEquals("a", linkedlist.get(0));
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipToKey_startWithFieldName() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.nextToken();
parser.skipToKey("title");
assertEquals(JsonToken.VALUE_STRING, parser.getCurrentToken());
assertEquals("foo", parser.getText());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParse_empty() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY);
parser.nextToken();
try {
parser.parseAndClose(HashMap.class);
fail("expected " + IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
// expected
}
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_intArray() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
parser = factory.createJsonParser(INT_ARRAY);
parser.nextToken();
int[] result = parser.parse(int[].class);
assertEquals(INT_ARRAY, factory.toString(result));
// check types and values
assertTrue(Arrays.equals(new int[] {1, 2, 3}, result));
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipChildren_object() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.skipChildren();
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipToKey_missing() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.skipToKey("missing");
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_anyType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
parser = factory.createJsonParser(ANY_TYPE);
parser.nextToken();
AnyType result = parser.parse(AnyType.class);
assertEquals(ANY_TYPE, factory.toString(result));
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipToKey_missingEmpty() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
parser.skipToKey("missing");
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParse_emptyGenericJson() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
GenericJson json = parser.parseAndClose(GenericJson.class);
assertTrue(json.isEmpty());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testParser_extendsGenericJson() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
// number types
parser = factory.createJsonParser(EXTENDS_JSON);
parser.nextToken();
ExtendsGenericJson result = parser.parse(ExtendsGenericJson.class);
assertEquals(EXTENDS_JSON, factory.toString(result));
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipChildren_array() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
parser.nextToken();
parser.skipToKey("entries");
parser.skipChildren();
assertEquals(JsonToken.END_ARRAY, parser.getCurrentToken());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipToKey_found() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.skipToKey("title");
assertEquals(JsonToken.VALUE_STRING, parser.getCurrentToken());
assertEquals("foo", parser.getText());
}
代码示例来源:origin: com.google.http-client/google-http-client-test
public void testSkipChildren_string() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
parser.skipToKey("title");
parser.skipChildren();
assertEquals(JsonToken.VALUE_STRING, parser.getCurrentToken());
assertEquals("foo", parser.getText());
}
内容来源于网络,如有侵权,请联系作者删除!