Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.json.JSON Exception : End of input at character 0

Tags:

json

android

I'm trying to parse json from android but I get this strange exception. My json data is

{"id":"1","owner":"1","name":"gravitas","description":"is a fest","start_time":"0000-00-00 00:00:00","end_time":"0000-00-00 00:00:00","venue":"vellore","radius":"10","lat":"11","lng":"11","type":"type","ownername":"dilip","noofpolls":0,"noofquizes":0,"peopleattending":0,"result":true}

and in android I do

JSONObject j =new JSONObject(response);
Event pst = gson.fromJson(j.toString(),  Event.class);

I get:

org.json.JSONException: end of input at character 0 of

What's wrong with it? Here is the code...

RestClient client = new RestClient("http://192.168.1.3/services/events/"+eve.getName());         
        try {
             Log.i("MY INFO", "calling boston");
            client.Execute(RequestMethod.POST);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String response = client.getResponse();
         Log.i("MY INFO", response);
         GsonBuilder gsonb = new GsonBuilder();
         Gson gson = gsonb.create();
         Event pst = null;

        try {
            JSONObject j =new JSONObject(response);
            pst = gson.fromJson(j.toString(),  Event.class);

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
like image 609
Rakon_188 Avatar asked Nov 20 '11 14:11

Rakon_188


1 Answers

Oops! my bad I was supposed to use GET method.that url doesn't respond to POST requests so I was getting the org.json.JSON Exception : End of input at character 0.its because of this I got null response which generated that exception.

like image 161
Rakon_188 Avatar answered Sep 18 '22 12:09

Rakon_188