/*
* Created on Jun 21, 2008
*/
package com.skaringa.javaxml.example;
import java.io.StringReader;
import java.util.Arrays;
import com.skaringa.javaxml.test.BooleanObj;
import com.skaringa.javaxml.test.ComplexArrayObj;
import com.skaringa.javaxml.test.StringObj;
import com.skaringa.json.parser.JsonParser;
/**
* Some examples to invoke the JsonParser directly.
*
*/
public class JsonParserExample {
/**
* TEST only.
*
* @param args
* @throws Exception
*/
public static void main(String args[]) throws Exception {
ClassLoader classLoader = JsonParser.class.getClassLoader();
String json = "{\"value\" : \"abcdef\\\"����\"}";
StringReader reader = new StringReader(json);
JsonParser parser = new JsonParser(reader, StringObj.class, classLoader);
parser.process();
System.out.println(parser.getObject().toString());
json = "{\"value1\" : 10,\n\"value2\":-10E6}";
reader = new StringReader(json);
parser = new JsonParser(reader, null, classLoader);
parser.process();
System.out.println(parser.getObject());
json = "{\"value\" : true}";
reader = new StringReader(json);
parser = new JsonParser(reader, BooleanObj.class, classLoader);
parser.process();
System.out.println(parser.getObject());
json = "[\"alpha\",\"beta\",\"gamma\"]";
reader = new StringReader(json);
parser = new JsonParser(reader, null, classLoader);
parser.process();
System.out.println(parser.getObject());
reader = new StringReader(json);
parser = new JsonParser(reader, String[].class, classLoader);
parser.process();
System.out.println(Arrays.asList((String[]) parser.getObject()));
json = "{\"myArray\":[{\"value\":\"0\"},{\"value\":\"1\"},{\"value\":\"2\"}]}";
reader = new StringReader(json);
parser = new JsonParser(reader, ComplexArrayObj.class, classLoader);
parser.process();
System.out.println(parser.getObject());
}
}