0
> {"-Kopv2EYUt7EeisRiiCz":{"deviceName":"LYF","fileUploadDate":"07\/12\/2017 2:00:57 PM"},
"-KopvA-cTtzgzSbsKTrw":{"deviceName":"LYF","fileUploadDate":"07\/12\/2017 2:01:29 PM",}}

How to parse all the "fileUploadDates" from the JsonObject ?

fileUploadDate = 07\/12\/2017 2:00:57 PM
fileUploadDate = "07\/12\/2017 2:01:29 PM
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57
Bivin OC
  • 131
  • 16
  • Refer this link https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android – Yyy Jul 13 '17 at 10:29
  • I suggest two options. The first is to retrieve your json object already filtered (so you can make a request with filtering params and the server send you the json filtered) and then you can parse it in a JsonObject. The second option is to retrieve the json, parse it in a JsonObject, then implement your own methods to filter by date. If you have problem with parsing into a JsonObject, there are a lot of solved questions in StackOverflow. This is one https://stackoverflow.com/questions/9605913/how-to-parse-json-in-android – Giacomo Lai Jul 13 '17 at 10:30

3 Answers3

3

Use GSON library

public void parseJson(String json){
        Gson gson = new Gson();
        Type stringStringMap = new TypeToken<Map<String, Map<String,String>>>(){}.getType();
        Map<String,Map<String,String>> map = gson.fromJson(json, stringStringMap);

        Iterator it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry)it.next();
            Map<String,String> innerMap = (Map<String,String>)pair.getValue();
            getInnerMapDetail(innerMap);
            it.remove(); // avoids a ConcurrentModificationException
        }
}
    public void getInnerMapDetail(Map<String,String> innerMap)
    {   
         String fileUploadDate = innerMap.get("fileUploadDate"); // you will get here
        }

    }
Mayur Raval
  • 3,250
  • 6
  • 34
  • 57
0

Try this for your Response to Parse

May Help you

try{
     JSONObject jsonObject = new JSONObject(response);
     List<String> keyList = getAllKeys(jsonObject);
     for(String key : keyList){

          JSONObject innerObject = jsonObject.getJSONObject(key);
          String deviceName = innerObject.getString("deviceName");
          String fileUploadDate = innerObject.getString("fileUploadDate");

          System.out.println(deviceName +"--"+ fileUploadDate);
      }
}catch(Exception e){
            e.printStackTrace();
}

This method will return keys

private List<String> getAllKeys(JSONObject jsonObject) throws JSONException{
    List<String> keys = new ArrayList<String>();

    Iterator<?> iterator = jsonObject.keys();
    while( iterator.hasNext() ) {
        String key = (String)iterator.next();
        keys.add(key);
    }
   return keys;
}
Mohammad nabil
  • 1,010
  • 2
  • 12
  • 23
-1

First you need to parse json objects and store in to String,like that

String fileUploadDate;
JSONObject -Kopv2EYUt7EeisRiiCz = new JSONObject;
fileUploadDate= sys.getString("fileUploadDate");

After you change string like that

String newfileUploadDate = string.replace("\", "");

you defiantly come to output.

sanket patel
  • 21
  • 10
  • For sure, replace method will help. First get the jsonstring as it is and then replace will do. I agree for above – priya raj Jul 13 '17 at 11:01