org.json.JSON例外:输入的字符0结束 [英] org.json.JSON Exception : End of input at character 0

查看:190
本文介绍了org.json.JSON例外:输入的字符0结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析来自Android的JSON,但我得到这个奇怪的例外。我的JSON数据是

  

{ID:1,主人:1,名:庄严,说明:是一个巨星,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}

和android的我

 的JSONObject J =新的JSONObject(响应);
事件PST = gson.fromJson(j.toString(),Event.class);
 

我得到:

  org.json.JSONException:输入端的字符0
 

有什么不好呢?继承人的code ...

  RestClient客户端=新RestClient(http://192.168.1.3/services/events/+ eve.getName());
        尝试 {
             Log.i(我的信息,叫波士顿);
            client.Execute(RequestMethod.POST);
        }赶上(例外五){
            e.printStackTrace();
        }

        串响应= client.getResponse();
         Log.i(我的信息,响应);
         GsonBuilder gsonb =新GsonBuilder();
         GSON GSON = gsonb.create();
         事件PST = NULL;

        尝试 {
            JSONObject的J =新的JSONObject(响应);
            PST = gson.fromJson(j.toString(),Event.class);

        }赶上(JSONException E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
 

解决方案

哎呀我的坏我应该使用GET method.that URL犯规响应POST请求,所以我听明白了org.json.JSON例外:输入结束在因为这样的性格0.its我得到了它产生的异常空响应。

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? heres 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();
        }

解决方案

oops my bad i was supposed to use GET method.that url doesnt 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.

这篇关于org.json.JSON例外:输入的字符0结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆