为了账号安全,请及时绑定邮箱和手机立即绑定

org.json.JSON异常:字符0处的输入结束

org.json.JSON异常:字符0处的输入结束

12345678_0001 2019-11-04 11:05:01
我正在尝试从android解析json,但出现了这个奇怪的异常。我的json数据是{“ 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”,“所有者名称”:“ dilip”,“ noofpolls”:0,“ noofquizes”:0,“人员参与”:0,“ result”:true}在Android中JSONObject j =new JSONObject(response);Event pst = gson.fromJson(j.toString(),  Event.class);我得到:org.json.JSONException: end of input at character 0 of它出什么问题了?这是代码...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();        }
查看完整描述

3 回答

?
斯蒂芬大帝

TA贡献1827条经验 获得超8个赞

糟糕!我不好,我应该使用GET方法.URL不响应POST请求,所以我得到了org.json.JSON异常:字符0.its的输入结束,因此我得到了生成该异常的空响应。


查看完整回答
反对 回复 2019-11-04
?
繁花如伊

TA贡献2012条经验 获得超12个赞

就我而言,我指的是一个函数的名字,甚至不存在。检查你的函数名的Web服务,纠正函数名后,它为我工作!


查看完整回答
反对 回复 2019-11-04
?
弑天下

TA贡献1818条经验 获得超8个赞

这是有关如何使用GSON进行解析的代码段


    Gson gson = new GsonBuilder().create();

    JsonParser jsonParser = new JsonParser();


     String response = client.getResponse();

    JsonObject jsonResp = jsonParser.parse(response).getAsJsonObject();

    // Important note: JsonObject is the one from GSON lib!

    // now you build as you like e.g.

    Event mEvent = gson.fromJson(jsonResp, Event.class);


...


查看完整回答
反对 回复 2019-11-04
  • 3 回答
  • 0 关注
  • 755 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信