---
title: "json与对象互转，json数组与对象数组互转"
author: "jayung"
date: "2015-07-08T16:31:15Z"
tags: []
categories: ["Web前端"]
slug: "json-json"
draft: false
lastmod: "2015-09-27T22:17:59Z"
id: 2225274
url: "https://jayung.iteye.com/blog/2225274"
---

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();
		}
```