求指點(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;
}
2015-06-01
log寫(xiě)的很清楚了,沒(méi)有獲取到j(luò)son字符串 null
2015-08-21
原因:JSON數(shù)據(jù)解析出來(lái)的字符串開(kāi)頭是null,而影響了格式,所以不能轉(zhuǎn)換。
解決:
//替換”null“
????????????????if(jsonString.startsWith("null")){
????????????????????jsonString?=?jsonString.substring(4);
????????????????}
2015-06-01