All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.java.test.TestParser Maven / Gradle / Ivy

Go to download

Jackson is a high-performance JSON processor (parser, generator)

There is a newer version: 0.9.5
Show newest version
package test;

import java.io.*;

import org.codehaus.jackson.*;

public class TestParser
{
    public static void main(String[] args)
        throws IOException
    {
        if (args.length != 1) {
            System.err.println("Usage: java ... TestParser [file]");
            System.exit(1);
        }
        JsonFactory f = new JsonFactory();
        JsonParser jp = f.createJsonParser(new File(args[0]));

        System.out.println("Parser: "+jp);

        JsonToken t;

        while ((t = jp.nextToken()) != null) {
            System.out.print("Token: "+t);
            if (t == JsonToken.FIELD_NAME) {
                System.out.print(", name = '"+jp.getText()+"'");
            } else if (t.toString().startsWith("VALUE")) {
                System.out.print(", value = \""+jp.getText()+"\"");
            }
            System.out.println();
        }

        jp.close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy