我想使用http://www.jsonschema2pojo.org/将我的JSON响应转换为Java,但是我正在查看的JSON没有引号,因此我无法使用此站点。关于如何使用引号生成JSON以利用此站点的任何想法?
答案 0 :(得分:1)
这对我有用:
public class addQuotes{
String dir = "enter file location here";
File quotes = new File(dir);
private String readFile(){
String q = "";
try(FileInputStream fin = new FileInputStream(dir)){
int s = (int) quotes.length();
byte[] r = new byte[s];
fin.read(r);
q = new String(r);
}catch(Exception e){
e.printStackTrace();
}
return q;
}
private void writeFile(FileOutputStream fos, String output) throws IOException{
byte[] data = output.getBytes();
fos.write(data);
}
public addQuotes() {
String add = readFile().replaceAll("(\\w+)", "\"$1\"");
try{
FileOutputStream fos = new FileOutputStream(dir);
writeFile(fos, add);
}catch(Exception e){
e.printStackTrace();
}
}
}