with my code, when i open a JSON file with app for smartphone JSON VIEWER, file is empty...i not see content...why?
Now,i show you my code how i save file json....
Thanks in advance everybody!
public String showResult(View v) throws IOException {
String result = "";
JsonObject json = new JsonObject();
for (Planet p : plAdapter.getBox()) {
if (p.isSelected()){
json.put("name",p.getName());
json.put("distance",p.getDistance());
json.put("quantity",p.getQuantità());
}
}
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();
}*/
FileWriter file = new FileWriter(path+"filename31.json");
file.write(result);
file.close();
System.out.println("Successfully wrote Json result to file.");
/*catch(IOException r){
}*/
System.out.println(result);
return result;
}
JsonObject class:
private static class JsonObject {
public void put(String name, String name1) {
}
}
Aucun commentaire:
Enregistrer un commentaire