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);
}
}
}
I want to change the fix txt file without "" from java to json format and then POST.
When that code is turned, the output is as follows.
Line 1: 아저시 -> 아저씨
Line 3: 아짐매 -> 암매장
Line 6: 부싼 -> 부산
Line 9: 쇠괴기 -> 쇠기기
I can divide this result value by key and value based on :, or I can just put all of this line in value. Can someone help me?
JsonArray or ArrayList?