如何在android中检索JSON对象

时间:2015-02-07 14:35:17

标签: java android arrays 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": "thamaraiselvam@live.com",
        "password": "0cc175b9c0f1b6a831c399e269772661",
        "name": "Thamaraiselvam"
      }
    },
    {
      "taxis": {
        "id": "3",
        "email": "arunesh@snowmanbranding.com",
        "password": "3bf575512fdce89fd4e3ba87a230b2f4",
        "name": "Arunesh"
      }
    },
    {
      "taxis": {
        "id": "4",
        "email": "a@a.com",
        "password": "0cc175b9c0f1b6a831c399e269772661",
        "name": "A"
      }
    }
  ]
}

如何使用Android从中提取电子邮件,密码和名称? 当我使用上面的代码时,我没有得到任何东西

1 个答案:

答案 0 :(得分: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");
           }
           }