ITeye博客

json与对象互转,json数组与对象数组互转

jayung · 2015-07-08 16:31 · json · Web前端 · Markdown

json与对象互转,json数组与对象数组互转 引用了 jackson-core-lgpl-1.9.2.jar jackson-mapper-lgpl-1.9.2.jar 特别说明的是:spring mvc里也是使用这两个包,通过注解@ResponseBody将返回的对象或map或list转成json输出到前端

Person person = new Person("张三", 23, "无", 105.00);

		ObjectMapper objectMapper = new ObjectMapper();
		try {
			
			String jsonStr = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(person);
			System.out.println("start, " + new Date());
			objectMapper.writerWithDefaultPrettyPrinter().writeValue(new File("person.json"), person);
			System.out.println("end, " +  new Date());
			System.out.println();
			System.out.print(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。