[英]JSON Replacing '.' with
我想要一個將JSON文件作為輸入和結果JSON文件的程序。 輸入文件包含以下內容:
{"empname":"surname.firstname","department.name":"production","salary":11254.42}
輸出文件必須用輸入JSON的'_'(下划線)替換'。'(點)。 預期的輸出:
{"empname":"surname_firstname","department_name":"production","salary":11254_42}
我想要使用JAVA而不使用序列化和反序列化的程序。 可以幫忙嗎?
如果您使用的是Java 7+:
String str = new String(Files.readAllBytes(Paths.get("in.json")), StandardCharsets.UTF_8)
.replace('.', '_');
Files.write(Paths.get("out.json"), str.getBytes("UTF-8"), StandardOpenOption.WRITE);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.