使用com.fasterxml.jackson将对象转换为JSON字符串或反转

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

示例:
import com.fasterxml.jackson.databind.ObjectMapper;


      Iterable areaItera = areaRepository.findAll();
		
	 StringWriter writer = new StringWriter();
         ObjectMapper mapper = new ObjectMapper();
         try {
			mapper.writeValue(writer, areaItera);
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
   
		System.out.println("areaString:"+writer.toString());

                Map> blockMap = mapper.readValue(writer.toString(), Map.class); 

                System.out.println(blockMap.toString());

转载于:https://my.oschina.net/zhangmaoyuan/blog/1606278

你可能感兴趣的:(json,python,java)