亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

求指點這個問題

private List<NewBean> getJsonData(String url) {
? ?List<NewBean> newBeanList = new ArrayList<NewBean>();//創建list
? ?//獲取json格式的數據

? ?try {
? ? ? ?String JsonString = readStream(new URL(url).openStream());
? ? ? ?System.out.println(JsonString);
? ? ? ?JSONObject jsonObject;
? ? ? ?NewBean newBean;
? ? ? ?jsonObject = new JSONObject(JsonString);
? ? ? ?JSONArray jsonArray = jsonObject.getJSONArray("data");
? ? ? ?System.out.println(jsonArray.length());
? ? ? ?for (int i = 0; i < jsonArray.length(); i++) {
? ? ? ? ? ?jsonObject = jsonArray.getJSONObject(i);
? ? ? ? ? ?newBean = new NewBean();
? ? ? ? ? ?newBean.setNewsIconUrl(jsonObject.getString("picSmall"));
? ? ? ? ? ?newBean.setNewsTitle(jsonObject.getString("name"));
? ? ? ? ? ?newBean.setNewsContent(jsonObject.getString("description"));
? ? ? ? ? ?newBeanList.add(newBean);
? ? ? ?}
? ?} catch (IOException e) {
? ? ? ?e.printStackTrace();
? ?} catch (JSONException e) {
? ? ? ?e.printStackTrace();
? ?}
? ?return newBeanList;

}

http://img1.sycdn.imooc.com//556b03eb0001264f08780396.jpg

正在回答

3 回答

log寫的很清楚了,沒有獲取到json字符串 null

0 回復 有任何疑惑可以回復我~

原因:JSON數據解析出來的字符串開頭是null,而影響了格式,所以不能轉換。

解決:

//替換”null“

????????????????if(jsonString.startsWith("null")){

????????????????????jsonString?=?jsonString.substring(4);

????????????????}


0 回復 有任何疑惑可以回復我~

http://img1.sycdn.imooc.com//556c1520000129b811450396.jpg我已經獲取到了json的數據,但是他說不能轉換為JSONObject

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android必學-異步加載
  • 參與學習       50616    人
  • 解答問題       333    個

了解Android中的異步加載處理方法,這是面試問的最多的知識點

進入課程

求指點這個問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號