How to find out json response is an empty JSON object in android?

Alireza Bideli :

I'm facing with the problem that I get an empty JSON Object from server.

How can I find out that JSON response from server is an empty JSON Object {} or others ? I set jObject!=null condition for it but it doesn't work.

Here is my Code :

JSONObject jObject = new JSONObject(response);

if (jObject!=null) {
    Toast.makeText(getApplicationContext(), R.string.successfull_unsubscribe, Toast.LENGTH_LONG).show();
    ShareData.saveData(getApplicationContext(), "simType", "null");
    ShareData.saveData(getApplicationContext(), "firstLaunch", "true");

    startActivity(new Intent(MainActivity2.this, WelcomeActivity.class));
    finish();
}
Sayantan Mandal :

You can try length check or toString.

eg: jObject.length() == 0

eg: jObject.toString().equals("{}")

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=305611&siteId=1