I am getting this above error when the json response values are null
{
"restaurant_area_min_order":null,
"restaurant_id":null
}.
The above error is appearing inside try catch block. When there is values inside restaurant_area_min_order and restaurant_id, The function is working fine without error. How can I check if the response data are null and continue the function without any error?
Here is my code.
private void getAreaMinOrders()
{
for(int i = 0; i < Utils.cart_restaurants.size(); i++)
{
RestaurantModel restaurant = Utils.cart_restaurants.get(i);
String restaurant_id = restaurant.getId();
String url = LinksConstants.BASE_URL + LinksConstants.CHECK_MINIMUM_ORDER;
RequestParams params = new RequestParams();
params.put("restaurant_id", restaurant_id);
params.put("area_id", city_id);
NetworkRestClient.post(url, params, new JsonHttpResponseHandler()
{
@Override
public void onStart()
{
super.onStart();
progressActivity.showLoading();
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response)
{
super.onSuccess(statusCode, headers, response);
try
{
if (response != null)
{
String restaurant_id = response.getString("restaurant_id");
String rest_area_min_order = null;
if(rest_area_min_order != null)
{
rest_area_min_order = response.getString("restaurant_area_min_order");
}
HashMap<String, Object> items_hash = (HashMap<String, Object>) rest_cart_hash.get(restaurant_id);
items_hash.put("rest_area_min_order", rest_area_min_order);
}
progressActivity.showContent();
}
catch (Exception ex)
{
GSLogger.e(ex);
showError();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, String errorResponse, Throwable throwable)
{
super.onFailure(statusCode, headers, errorResponse, throwable);
showError();
if (AppConstants.DEBUG_MODE)
showToast(errorResponse);
}
}); //end of NetworkRestClient.post
} //end of for
}