由於某種原因,我可以將整個數組讀回來,但是當我嘗試選擇一個段時,它不讓我看到數組中的段過去,數組長度等於1,就像所有被壓扁成一個元素。這是我的代碼:解析JSONObject中的JSONArray問題
https://github.com/yehudaclinton/Mytest/blob/master/TestHTTP.java
try { Object obj = parser.parse(result); JSONObject jsonObject = (JSONObject) obj; JSONArray items = (JSONArray) jsonObject.get("items"); Log.d(TAG, "items length: " + items.size());//for some reason is not more than 1 String name = ""; //the the following is supposed to return just the title of book for (int i = 0; i < items.size(); i++) { JSONObject item = (JSONObject) items.get(i);//if 'i' equals more then one program crashes if(item.get("title")!=null) {//only get the title JSONObject theTitle = (JSONObject) item.get("title"); name = (String) theTitle.get("title"); } }
結果=名稱;
什麼是堆棧跟蹤? –