我創建與下面的代碼JSONObject
但可變正顯示出甚至其初始化後null
:JSON對象不能inintialised
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("username", "pradyut");
jsonObject.put("password", "5F4DCC3B5AA765D61D8327DEB882CF99");
} catch (JSONException e) {
e.printStackTrace();
Log.i("log", "json exception : " + e.toString());
}
if (jsonObject == null) {
Log.i("log", "the json object is not null");
// this part is showing everytime.
} else {
Log.i("log", "the json object is null");
}
我沒有得到任何的異常。
這是爲什麼發生?
你的if語句的條件是錯誤的。 == null意味着它檢查它是否爲空。 –
運行這段代碼沒有錯誤?任何日誌/調試信息? –
如果你不導出到json,你可能會考慮使用字典嗎? – David