android–JSONObject的大小JSON字符串不起作用

android–JSONObject的大小JSON字符串不起作用,第1张

概述protectedclasssaveBtnClickHandlerimplementsOnClickListener{@OverridepublicvoidonClick(Viewv){StringjsonRest=loadJsonDataFromURL("http:/hirddhaba.appspot.com/api/v1/circle/condensed/data/?circle_id=1");try

protected class saveBtnClickHandler implements OnClickListener{    @OverrIDe    public voID onClick(VIEw v) {           String JsonRest = loadJsonDataFromURL("http://thirddhaba.appspot.com/API/v1/circle/condensed/data/?circle_ID=1");    try {            JsONObject JsonObj = new JsONObject(JsonRest);          } catch (JsONException e) {              androID.util.Log.e("JsON Parser", "Error parsing data " + e.toString());        }    }}protected String loadJsonDataFromURL(String url){     String JsonStr = null;    try {         httpClIEnt httpclIEnt = new DefaulthttpClIEnt();            httpResponse response = httpclIEnt.execute(new httpGet(url));            Statusline statusline = response.getStatusline();            if(statusline.getStatusCode() == httpStatus.SC_OK){                ByteArrayOutputStream out = new ByteArrayOutputStream();                response.getEntity().writeto(out);                out.close();                 JsonStr = out.toString();            } else{                //Closes the connection.                response.getEntity().getContent().close();                throw new IOException(statusline.getReasonPhrase());            }    } catch (Exception e) {        // Todo: handle exception    }    return JsonStr;}

 
上面的代码工作正常.但是此JsON(Link)URL字符串未转换为JsON对象.我认为这是大字符串也添加错误屏幕截图.

解决方法:

您的测试数据基于[]包含在数组中.您需要将其解析为Json数组而不是Json对象.

JsONArray JsonArr = new JsONArray(JsonRest);  
总结

以上是内存溢出为你收集整理的android – JSONObject的大小JSON字符串不起作用全部内容,希望文章能够帮你解决android – JSONObject的大小JSON字符串不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115588.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存