第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

求指點(diǎn)這個(gè)問(wèn)題

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

? ?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寫(xiě)的很清楚了,沒(méi)有獲取到j(luò)son字符串 null

0 回復(fù) 有任何疑惑可以回復(fù)我~

原因:JSON數(shù)據(jù)解析出來(lái)的字符串開(kāi)頭是null,而影響了格式,所以不能轉(zhuǎn)換。

解決:

//替換”null“

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

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

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


0 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//556c1520000129b811450396.jpg我已經(jīng)獲取到了json的數(shù)據(jù),但是他說(shuō)不能轉(zhuǎn)換為JSONObject

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Android必學(xué)-異步加載
  • 參與學(xué)習(xí)       50617    人
  • 解答問(wèn)題       326    個(gè)

了解Android中的異步加載處理方法,這是面試問(wèn)的最多的知識(shí)點(diǎn)

進(jìn)入課程

求指點(diǎn)這個(gè)問(wèn)題

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)