The object is written to a file in json format


将 list 对象以json格式写入到文件中




try
{ ObjectMapper mapper = new ObjectMapper(); String value = mapper.writeValueAsString(list); OutputStream out =new FileOutputStream("D:/file/oms.json"); byte[] b=value.getBytes(); for(int i=0;i<b.length;i++){ out.write(b[i]); } out.close();
}
catch (IOException e) { logger.info ( "Serialization failure ...... " ); e.printStackTrace ();
}
结果如下所示:

[{"id":"000000151","length":22.2}, {"id":"000000161","length":23.37}, {"id":"000000160","length":23.37} ]

 

Guess you like

Origin www.cnblogs.com/JonaLin/p/11622306.html