ho una risposta di ritorno da un server e mi aspetto un valore String, così ho scritto questo per analizzarloJSON.getString non restituisce nulla
public String getMessageFromServer(JSONObject response) {
String msg = response.getString("message");
return msg;
}
poi, quando uso questo nel mio codice e ottenere un valore null
dal server, la funzione non restituisce null
, restituisce invece "null"
.
Ho visto this bug report, ma non vedo una soluzione.
EDIT:
ho un piccolo hack per risolvere questo ma è brutto e sto cercando una soluzione migliore:
public String getMessageFromServer(JSONObject response) {
Object msg = response.get("message");
if(msg == null) {
return null;
}
return (String) msg;
}
che sembra OK per me. –
è ok, ma è un brutto trucco e non mi piace – thepoosh
Perché è brutto o hack? Lo stai facendo bene –