java利用Jackson框架解析JSON

发布时间:2013-02-19 05:35:42

 

官方网址 http://wiki.fasterxml.com/JacksonInFiveMinutes

下载地址 http://wiki.fasterxml.com/JacksonDownload

我提供一个例子:

public class Test {
	private int a = 123;
	private String b = "懂";

	public static void main(String[] args) throws IOException {
		ObjectMapper objectMapper = new ObjectMapper();
		String str = objectMapper.writeValueAsString(new Test());
		System.err.println("-------------" + str);
	}

	public int getA() {
		return a;
	}

	public String getB() {
		return b;
	}

}

打印结果:
-------------{"a":123,"b":"懂"}