将文件转换为JSON

时间:2018-09-19 10:52:31

标签: java json fileparsing

我有一个以下格式的文件:

TEST1 =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL= TCP)(Host= test100.xyz.com)(Port= 1521))
  (CONNECT_DATA = (SID = TEST1))
)
TEST2 =
(DESCRIPTION =
  (ADDRESS = (PROTOCOL= TCP)(Host= test101.xyz.com)(Port= 1521))
  (CONNECT_DATA = (SID = TEST2))
)

有没有一个我可以用来解析并存储为JSON的库?

1 个答案:

答案 0 :(得分:-2)

您可以尝试以下代码-

File file=new File("D:\\tnames.txt");
    String str=FileUtils.readFileToString(file);

    str = str.replace("(", "{");
    str = str.replace(")", "}");
    str = str.replace("=", ":");

    String jsonString = "{" + str + "}";
    System.out.println(jsonString);