Uso il framework Play. Ho un JSONObject che ha una struttura come la seguente (Come in console è stampato)Scrittura di JSONObject in un file
{
"rows_map":{
"220":["mahesh",
"outfit:bmtech,app:salesreport,uuname,ffname,llname",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5",
null
],
"221":["mahesh",
"outfit:bmtech,app:salesreport,uuname,ffname,llname",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5",
null
],
"222":["mahesh",
"outfit:bmtech,app:salesreport,uuname,ffname,llname",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5",
null
],
"223":["mahesh",
"outfit:bmtech,app:salesreport,uuname,ffname,llname",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5",
null
]
},
"columns_map":["Sender",
"Message Received",
"Device",
"Time"
]
}
voglio scrivere questo JSONObject in un file. Ecco il codice
String path = "/var/www/html/Prj/public/CacheLayer/Incoming_Cache/CacheFileMgr.cache";
ObjectOutputStream outputStream = null;
try{
outputStream = new ObjectOutputStream(new FileOutputStream(path));
System.out.println("Start Writings");
outputStream.writeObject(object);
outputStream.flush();
outputStream.close();
}catch (Exception e){
System.err.println("Error: " + e);
}
Quanto sopra non scrive correttamente nel file. Si verifica un errore di serializzazione.
Si prega di inviare il messaggio di errore insieme al codice. Potrebbe essere un errore di autorizzazione, o potrebbe essere qualcosa di semplice come 'JSONObject' non implementa l'interfaccia' Serializable', che è ciò che è necessario affinché '.writeObject()' funzioni (http: // download. oracle.com/javase/1,5.0/docs/api/java/io/Serializable.html). – jefflunt