Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a JSONException: end of input at character 0

Tags:

json

android

I have an API in php, that sends data in JSON format. I made the following code, that works fine when I am on wifi. But when I want to download the data from the API when I am on 3g, I receive the following exception: JSONException: End of input at character 0 of

I have no idea why it does work on wifi, but it doesn't on mobile internet. My code:

        JSONObject json = getJSONfromURL("http://api.myurl.com/users.json");

        JSONArray objects = json.getJSONArray("objects");
        db.setLockingEnabled(false);
        db.beginTransaction();

        for (int i = 0; i < objects.length(); i++) {
            JSONObject e = objects.getJSONObject(i);

            if(e.getString("UID") != "-1"){
                ContentValues values = new ContentValues();
                //DO DATABASE INSERT. REMOVED THIS CODE FOR READABILITY
                alldata_mProgressDialog.incrementProgressBy(1);
            }
        }

Anyone that can help me out?

like image 961
harmjanr Avatar asked Jan 05 '12 09:01

harmjanr


1 Answers

You are probably getting a blank response. Its not null but the response is empty. So you are getting this error and not a Nullpointer exception

like image 84
amiekuser Avatar answered Sep 21 '22 21:09

amiekuser