当前位置: 首页>>代码示例>>Java>>正文


Java JsonParser.next方法代码示例

本文整理汇总了Java中javax.json.stream.JsonParser.next方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.next方法的具体用法?Java JsonParser.next怎么用?Java JsonParser.next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.stream.JsonParser的用法示例。


在下文中一共展示了JsonParser.next方法的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;
            }
        }
    }
 
开发者ID:readlearncode,项目名称:JSON-Processing-with-Java-EE,代码行数:27,代码来源:StreamingExample1.java

示例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;
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:18,代码来源:BookDeserializer.java

示例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;
    }
 
开发者ID:readlearncode,项目名称:JSON-Processing-with-Java-EE,代码行数:21,代码来源:StreamingExample2.java

示例4: 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 ();
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:20,代码来源:UTF8TextJsonParserTest.java

示例5: 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);
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:19,代码来源:BsonParserTest.java

示例6: 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);;
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:21,代码来源:JsonStructureParserTest.java

示例7: 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);
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:18,代码来源:TextJsonParserTest.java

示例8: deserialize

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public String deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    while (parser.hasNext()) {
        JsonParser.Event event = parser.next();
        if (event == JsonParser.Event.KEY_NAME) {
            String keyName = parser.getString();
            if (keyName.equals("id")) {
                return ctx.deserialize(String.class, parser);
            }
        }
        parser.next();
    }
    return "";
}
 
开发者ID:readlearncode,项目名称:Java-EE-8-Sampler,代码行数:15,代码来源:BookDeserializer.java

示例9: testNull3

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testNull3 ()
{
	String json = "[ nul ]";

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:13,代码来源:UTF8TextJsonParserErrorTest.java

示例10: testError7

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
@SuppressWarnings ("resource")
public void testError7 ()
{
	String json = "{ \"a\" : 1 \u0000]";

	thrown.expect (JsonParsingException.class);
	thrown.expectMessage ("Parsing error at line 1, column 11, offset 10: unexpected character '\\u0000'");

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:16,代码来源:UTF8TextJsonParserErrorTest.java

示例11: testNumber4

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
@SuppressWarnings ("resource")
public void testNumber4 ()
{
	String json = "[ -1e- ]";

	thrown.expect (JsonParsingException.class);
	thrown.expectMessage ("Parsing error at line 1, column 7, offset 6: unexpected character ' '");

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:16,代码来源:UTF8TextJsonParserErrorTest.java

示例12: testTrue4

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testTrue4 ()
{
	String json = "[ trua ]";

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:13,代码来源:UTF8TextJsonParserErrorTest.java

示例13: testNumber8

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test
@SuppressWarnings ("resource")
public void testNumber8 ()
{
	String json = "[ 0. ]";

	thrown.expect (JsonParsingException.class);
	thrown.expectMessage ("Parsing error at line 1, column 5, offset 4: unexpected character ' '");

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:16,代码来源:UTF8TextJsonParserErrorTest.java

示例14: deserialize

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Override
public Crate deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    Crate result = new Crate();
    while (parser.hasNext()) {
        final JsonParser.Event next = parser.next();
        if (next.equals(JsonParser.Event.KEY_NAME) && parser.getString().equals("date-converted")) {
            parser.next();
            result.date = ctx.deserialize(Date.class, parser);
            break;
        }
    }
    return result;
}
 
开发者ID:eclipse,项目名称:yasson,代码行数:14,代码来源:CrateDeserializerWithConversion.java

示例15: testFalse3

import javax.json.stream.JsonParser; //导入方法依赖的package包/类
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testFalse3 ()
{
	String json = "[ fal ]";

	JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
	for (;;)
	{
		p.next ();
	}
}
 
开发者ID:coconut2015,项目名称:cookjson,代码行数:13,代码来源:UTF8TextJsonParserErrorTest.java


注:本文中的javax.json.stream.JsonParser.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。