Java 添加引号以将JSON转换为POJO
我想用它将我的JSON响应转换为Java,但是我正在查看的JSON没有引号,因此我无法使用此站点。关于如何生成带引号的JSON以利用此站点,您有什么想法吗?这对我很有用:Java 添加引号以将JSON转换为POJO,java,android,json,pojo,Java,Android,Json,Pojo,我想用它将我的JSON响应转换为Java,但是我正在查看的JSON没有引号,因此我无法使用此站点。关于如何生成带引号的JSON以利用此站点,您有什么想法吗?这对我很有用: public class addQuotes{ String dir = "enter file location here"; File quotes = new File(dir); private String readFile(){ String q = ""; try(FileIn
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();
}
}
}