Skip to content Skip to sidebar Skip to footer

How To Print Message When Json Response Has No Fileds?

I am using this tutorial http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ for json parsing,and in my app response and everything works fine,but what if response h

Solution 1:

as per this example try this..

protectedvoidonPostExecute(Void result) {
    super.onPostExecute(result);

    if(contacts == null || contacts.length() == 0){                
         Toast.makeText(getApplicationContext(), "No Data",Toast.LENGTH_SHORT).show();       
    }

    // Dismiss the progress dialogif (pDialog.isShowing())
         pDialog.dismiss();          
}

Solution 2:

if (response=null)
Toast.maketext(this,"No response",Toast.lenght_long).show();

Solution 3:

// Getting JSON Array node
contacts = jsonObj.getJSONArray(TAG_CONTACTS);
if(contacts == null || contacts.length() == 0){
    // Do your thing..
}

Solution 4:

You can try to check if your response is null or with length0

if (response=null || response.length == 0 )
Toast.makeText(this,"No contacts found.",Toast.LENGTH_LONG).show();

Solution 5:

Try this as per example code

// Getting JSON Array node
contacts = jsonObj.getJSONArray(TAG_CONTACTS);
if(contacts == null || contacts.length() == 0){
   // show toast in doinbackground using runOnUiThread
   runOnUiThread(new Runnable() {

                    publicvoidrun() {

                      Toast.makeText(getApplicationContext(), "No response", Toast.LENGTH_SHORT).show();

                       }
                    });
}

Post a Comment for "How To Print Message When Json Response Has No Fileds?"