本文整理汇总了Java中javax.json.stream.JsonParser.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.hasNext方法的具体用法?Java JsonParser.hasNext怎么用?Java JsonParser.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.stream.JsonParser
的用法示例。
在下文中一共展示了JsonParser.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseJsonString
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private static void parseJsonString() {
JsonParser parser = Json.createParser(new StringReader(JSON));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
switch (event) {
case START_ARRAY:
case END_ARRAY:
case START_OBJECT:
case END_OBJECT:
case VALUE_FALSE:
case VALUE_NULL:
case VALUE_TRUE:
System.out.println(event.toString());
break;
case KEY_NAME:
System.out.print(event.toString() + " " + parser.getString() + " - ");
break;
case VALUE_STRING:
case VALUE_NUMBER:
System.out.println(event.toString() + " " + parser.getString());
break;
}
}
}
示例2: deserialize
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public Book deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
Book book = null;
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
if (event == JsonParser.Event.KEY_NAME) {
String className = parser.getString();
parser.next();
try {
book = ctx.deserialize(Class.forName(className).asSubclass(Book.class), parser);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
return book;
}
示例3: retrieveValue
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
public String retrieveValue(final String key_to_find, final String json) {
JsonParser parser = Json.createParser(new StringReader(json));
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
switch (event) {
case KEY_NAME:
if (parser.getString().equalsIgnoreCase(key_to_find)) {
event = parser.next();
if (event == VALUE_STRING || event == VALUE_NUMBER) {
return parser.getString();
}
}
break;
}
}
return null;
}
示例4: testGetInt
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetInt () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
int[] ints = new int[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
ints[count++] = p.getInt ();
}
}
p.close ();
Assert.assertArrayEquals (new int[]{ 1234, 1942892530, -115429390, 12345, 1234, 1942892530, -115429390, 12345, 1 }, ints);
}
示例5: testNumber1
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber1 ()
{
String json = "{\"abc\" : 0 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("0", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例6: testNumber3
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber3 ()
{
String json = "{\"abc\" : -0.1 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("-0.1", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例7: eventCount
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
private void eventCount (String f, int expect) throws IOException
{
File file = new File (f.replace ('/', File.separatorChar));
JsonValue value;
TextJsonParser p = getJsonParser (file);
p.next ();
value = p.getValue ();
p.close ();
JsonProvider provider = new CookJsonProvider ();
JsonParser p2 = createParser (provider, value);
int count;
for (count = 0; p2.hasNext (); ++count)
p2.next ();
p2.close ();
Assert.assertEquals (expect, count);;
}
示例8: testGetDecimal
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetDecimal () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 0);
BigDecimal[] decimals = new BigDecimal[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
decimals[count++] = p.getBigDecimal ();
}
}
p.close ();
Assert.assertArrayEquals (new BigDecimal[]{ new BigDecimal (1234), new BigDecimal (12345678901234L), new BigDecimal ("1234567890123412345678901234"), new BigDecimal (12345.5), new BigDecimal (1234), new BigDecimal (12345678901234L), new BigDecimal ("1234567890123412345678901234"), new BigDecimal (12345.5), new BigDecimal (1) }, decimals);
}
示例9: testGetInt_2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetInt_2 () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 1);
int[] ints = new int[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
ints[count++] = p.getInt ();
}
}
p.close ();
Assert.assertArrayEquals (new int[]
{ 1234, 1942892530, -115429390, 12345, 1234, 1942892530, -115429390, 12345, 1 }, ints);
}
示例10: testZero1
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testZero1 ()
{
String json = "[ -0 ]";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("-0", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例11: testGetLong_2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetLong_2 () throws IOException
{
File file = new File ("../tests/data/types.json".replace ('/', File.separatorChar));
JsonParser p = getJsonParser (file, 1);
long[] longs = new long[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
longs[count++] = p.getLong ();
}
}
p.close ();
Assert.assertArrayEquals (new long[]
{ 1234, 12345678901234L, 7888426545362939890L, 12345, 1234, 12345678901234L, 7888426545362939890L, 12345, 1 },
longs);
}
示例12: testNumber4
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber4 ()
{
String json = "{\"abc\" : 0.1e2 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("0.1e2", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例13: testNumber5
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testNumber5 ()
{
String json = "{\"abc\" : -0.1e2 }";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("-0.1e2", p.getString ());
break;
default:
break;
}
}
p.close ();
}
示例14: testGetDecimal
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testGetDecimal () throws IOException
{
File file = new File ("../tests/data/types.bson".replace ('/', File.separatorChar));
JsonParser p = new BsonParser (new FileInputStream (file));
BigDecimal[] decimals = new BigDecimal[9];
int count = 0;
while (p.hasNext ())
{
if (p.next () == Event.VALUE_NUMBER)
{
decimals[count++] = p.getBigDecimal ();
}
}
p.close ();
BigDecimal d = new BigDecimal (new BigInteger ("1234567890123412345678901234").doubleValue ());
Assert.assertArrayEquals (new BigDecimal[]{ new BigDecimal (1234), new BigDecimal (12345678901234L), d, new BigDecimal (12345.5), new BigDecimal (1234), new BigDecimal (12345678901234L), d, new BigDecimal (12345.5), new BigDecimal (1) }, decimals);
}
示例15: testZero2
import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
public void testZero2 ()
{
String json = "[ 0e0 ]";
JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
while (p.hasNext ())
{
switch (p.next ())
{
case VALUE_NUMBER:
Assert.assertEquals ("0e0", p.getString ());
break;
default:
break;
}
}
p.close ();
}