2015-02-07 48 views
-2

JSON對象,我有這個代碼試圖從JSON對象中提取電子郵件如何檢索機器人

JSONArray one = reader.getJSONArray("taxis"); 

for (i = 0; i < one.length(); i++) { 
    two = one.getJSONObject(i); 
    distance = two.getString("taxis"); 
    three = two.getJSONArray("taxis"); 
     for (j = 0; j < three.length(); j++) { 
      four = three.getJSONObject(j); 
      distance = four.getString("email"); 
     } 
    } 

我得到JSON結果這樣

{ 
    "taxis": [ 
    { 
     "taxis": { 
     "id": "1", 
     "email": "[email protected]", 
     "password": "0cc175b9c0f1b6a831c399e269772661", 
     "name": "Thamaraiselvam" 
     } 
    }, 
    { 
     "taxis": { 
     "id": "3", 
     "email": "[email protected]", 
     "password": "3bf575512fdce89fd4e3ba87a230b2f4", 
     "name": "Arunesh" 
     } 
    }, 
    { 
     "taxis": { 
     "id": "4", 
     "email": "[email protected]", 
     "password": "0cc175b9c0f1b6a831c399e269772661", 
     "name": "A" 
     } 
    } 
    ] 
} 

如何提取電子郵件,使用Android的密碼和名稱? 我沒有得到任何東西,當我上面的幾個JSON解析庫代碼

+2

有什麼用處? – 2015-02-07 14:40:37

+0

請再次看到我的問題花花公子 – Thamaraiselvam 2015-02-07 14:48:07

+0

變量的命名可以改進,以減少混淆。另外你的JSON結構中只有一個數組... – Henry 2015-02-07 14:56:07

回答

1
JSONArray albums = reader.getJSONArray("map"); 

      // looping through All albums 
      for(j= 0; j < albums.length(); j++){ 
       JSONObject codes = albums.getJSONObject(j); 

       String album_id = codes.getString("location"); 

       album_id="["+album_id+"]"; 
       JSONArray jsonArray = new JSONArray(album_id); 
       for(k= 0; k < jsonArray.length(); k++){ 
        JSONObject codess = jsonArray.getJSONObject(k); 

     distance[k] = codess.getString("id"); 
      } 
      }