Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

android - Getting a JSONException: end of input at character 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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...