簡體   English   中英

JSON替換“。” 與

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM