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



将 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("序列化失败......"); e.printStackTrace();
}
结果如下所示:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM