title: Unable to Getstring from jsonObject
body: <p>I have this JSON string.</p>
  
  <pre><code>{
      "drtest": {
          "password":"dr123",
          "presence": {
              "lastSeen":1485992132269,
              "status":"offline"
           },
           "role":"Doctor",
           "speciality":"Physiotherapist",
           "token":"f80ve0sY6Ak:APA91bGLPlmy7b_iyqtW9ioG11TOx3xTB9BJgb1vvBK4YRo-28DyXWydg476TvjzaxyNB3kTTMn0BycEDm9UJHAPeoWzV-vFrwN46hg-GKSI6DH1s9zrH8h834c2whEdr12XqWN-4jrs"
       },
      "patient": {
           "password":"pat123",
           "presence": {
               "lastSeen":1486046501150,
               "status":"online"
           },
           "role":"Patient",
           "token":"f80ve0sY6Ak:APA91bGLPlmy7b_iyqtW9ioG11TOx3xTB9BJgb1vvBK4YRo-28DyXWydg476TvjzaxyNB3kTTMn0BycEDm9UJHAPeoWzV-vFrwN46hg-GKSI6DH1s9zrH8h834c2whEdr12XqWN-4jrs"
      }
  }
  </code></pre>
  
  <p>Firstly I was keeping the track of doctor role, but now I have to keep track on speciality as well. However I am trying the code which supposed to work correct but it is not working as expected.</p>
  
  <p>As you can see only one entity has speciality data and other does not contain the field of speciality. How can I parse speciality data if it is there and ignore if there's no speciality field in the JSON?</p>
  
  <p>I am using this code :</p>
  
  <pre><code>    try {
          contactList.clear();
          JSONObject obj = new JSONObject(s);
          Iterator i = obj.keys();
          String key = "";
  
          while (i.hasNext()) {
              key = i.next().toString();
              JSONObject singleUser = (JSONObject) obj.get(key);
              String role = singleUser.get("role").toString();
  
              JSONObject singleUser2 = (JSONObject) obj.get(key);
  
              String tpesu= singleUser2.getString("speciality");
  
              // no success here? need help want this value...
              Log.e("specialittyyyyyyy",tpesu+"");
  
              JSONObject presence = singleUser.getJSONObject("presence");
              String status = presence.getString("status");
  
              if (!key.equals(UserDetails.username)) {
                  if (role.equals("Doctor")) {
                      HashMap&lt;String, String&gt; docs = new HashMap&lt;&gt;();
                      docs.put("name", key);
                      docs.put("status", status);
                      Log.e("status ", status + "");
                      contactList.add(docs);
                  }
              }
              totalUsers++;
          }
      } catch (JSONException e) {
          e.printStackTrace();
      }
  </code></pre>