我想把没有" "的txt文件从java改成json格式然后POST

问题描述 投票:0回答:0
package com.example.spell.controller;


import org.json.simple.parser.JSONParser;
import org.springframework.web.bind.annotation.*;
import org.json.simple.JSONObject;
import org.springframework.stereotype.Controller;

import java.io.FileNotFoundException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import java.io.IOException;
import java.io.*;
import java.util.HashMap;
import java.io.InputStreamReader;

public class MainController {

        @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home() {
        return "home";
    }

@ResponseBody
@RequestMapping(value = "/test", method = RequestMethod.POST)
public void init(@RequestBody HashMap<String, List> map) {
    JSONObject jsonObject = new JSONObject(map);

    try {
        FileWriter file = new FileWriter("./mine1.json");
        System.out.println(jsonObject.get("data").toString().replace(",", ",\n"));
        file.write(jsonObject.get("data").toString().replace(",", ",\n"));
        file.flush();
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String s;
    Process p;
    try {
        String[] cmd = {"/bin/sh", "-c", "hunspell -u -d ko_KR mine1.json > fix.txt"};
        p = Runtime.getRuntime().exec(cmd);
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((s = br.readLine()) != null)
            System.out.println(s);
        p.waitFor();
        System.out.println("exit: " + p.exitValue());
        p.destroy();
    } catch (Exception e) {
    }
    try {
        File fix = new File("./fix.txt");
        FileReader filereader = new FileReader(fix);
        BufferedReader bufReader = new BufferedReader(filereader);
        String line = "";
        while ((line = bufReader.readLine()) != null) {
            System.out.println(line);
        }
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(line);
        JSONObject jsonObj = (JSONObject) obj;

        String code = (String) jsonObj.get("");
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        System.out.println(e);
    }
  }
}

我想把没有“”的修复txt文件从java改成json格式再POST。

当该代码被打开时,输出如下。

"

第一行: 한저시 -\u003e 한저씨

\n""

第 3 行:한짐매 -\u003e 암매장

\n"

第 6 行:부싼 -> 부산

9号线:쇠괴기 -> 쇠기기

我可以将这个结果值除以基于 : 的键和值,或者我可以将所有这一行都放入值中。有人可以帮助我吗?

JsonArray 还是 ArrayList?

java spring post hunspell
© www.soinside.com 2019 - 2024. All rights reserved.