Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 添加引号以将JSON转换为POJO_Java_Android_Json_Pojo - Fatal编程技术网

Java 添加引号以将JSON转换为POJO

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

我想用它将我的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+)", "\"$1\"");
    try{
        FileOutputStream fos =  new FileOutputStream(dir);
        writeFile(fos, add);
    }catch(Exception e){
        e.printStackTrace();
    }
  }
}