Getting JSON exception: end of character input 0

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

I have no idea why it works on Wi-Fi, but it does not work on mobile Internet. My code is:

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); } } 

Can anyone help me out?

+8
json android
source share
7 answers

You probably get an empty answer. Its value is not zero, but the answer is empty. This way you get this error and not a Nullpointer exception

+40
source share

Perhaps you get a default response with default values. Such an error occurs when you do not send your requests properly or send with the wrong parameters. Check It Out

+4
source share

Check if you are requesting permission to use the Internet.

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

in the android manifest

Check out others at Permissions Overview @https: //developer.android.com .

+3
source share

Sometimes this error occurs because the json encode function requires that all incoming data be encoded in UTF-8 encoding.

Try adding mysqli_set_charset($con, 'utf8'); to your php.

0
source share

This type of error occurs when the response is zero. Json print respawn in logcat

Log.e ("answer", "" + answer), or you can also check the answer at the postman.

0
source share

I got this error while debugging Android app on Android Studio via USB. The connection attempt failed with one tablet, but not with my regular test tablet. It turned out that the failure occurred due to the fact that I did not turn on the WIFI settings on the faulty computer. So I turned on WIFI on it, and it connected to the OK server.

0
source share

I get the same error. I am new to Android. so connecting to a database is like a horror movie. I mentioned internet resolution as well.

0
source share

All Articles