how create JSON file with variable of type String
<p>i have a variable of type <code>String</code> and i need create a json file with this variable.</p>

<p>I need to create <code>JSON file</code> with content of variable <code>"result"</code>.</p>

<p>I hope that you can help me!</p>

<p>Thanks in advance!</p>

<pre><code>@TargetApi(Build.VERSION_CODES.KITKAT)
public String showResult(View v) throws IOException {

        String  result = "";

        Gson json = new Gson();
        for (Planet p : plAdapter.getBox()) {
            if (p.isSelected()){
                /*json.put("name",p.getName());
                json.put("distance",p.getDistance());
                json.put("quantity",p.getQuantità());*/
                result=result+json.toJson(p);


            }
        }
         //result=json.toString();

        String path = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/droidText/";

        //FileWriter file=null;

    /*  try {
            file = new FileWriter(path+"filename5.json");
            file.write(result);


        }catch(IOException ie){}
        finally{


            file.flush();
            file.close();
        }*/try(FileWriter file = new FileWriter(path + "filename.json"))  {
        //  file=new FileWriter(path+"filename100.json");
        /*FileWriter file = new FileWriter(path+"filename31.json");
            file.write(result);
        file.close();
        */
            json.toJson(result);
            //System.out.println("Successfully wrote Json result to file.");
        /*catch(IOException r){

        }*/
        }catch (IOException e){

        }
        System.out.println(result);
        return result;

    }
</code></pre>