添加引号以将 JSON 转换为 POJO
Add Quotes to Convert JSON to POJO
我想使用 http://www.jsonschema2pojo.org/ 将我的 JSON 回复转换为 Java,但是我正在查看的 JSON 没有引号,因此我无法使用它地点。关于如何生成带引号的 JSON 以利用此网站的任何想法?
这对我有用:
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+)", "\"\"");
try{
FileOutputStream fos = new FileOutputStream(dir);
writeFile(fos, add);
}catch(Exception e){
e.printStackTrace();
}
}
}
我想使用 http://www.jsonschema2pojo.org/ 将我的 JSON 回复转换为 Java,但是我正在查看的 JSON 没有引号,因此我无法使用它地点。关于如何生成带引号的 JSON 以利用此网站的任何想法?
这对我有用:
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+)", "\"\"");
try{
FileOutputStream fos = new FileOutputStream(dir);
writeFile(fos, add);
}catch(Exception e){
e.printStackTrace();
}
}
}