How do I parse a field from a deep nested json object using Gson and retrofit in android?

后端 未结 3 1056
南旧
南旧 2021-01-26 01:06

I have a unique situation where I have to get certain times from a json\'s deeply nested object. It\'s a little complex, I couldn\'t find a solution so looking for ideas and way

3条回答
  •  生来不讨喜
    2021-01-26 01:42

    You will have to do something like this :

    JSONArray array = new JSONArray(result);
    for (int i = 0; i < array.length(); ++i) {
    JSONObject jObj = array.getJSONObject(i);
    
    String busyAt = jObj.getString("busyAt");
    // convert it to json array 
    JSONArray busyAtArray = new JSONArray(busyAt)
    String endedAt = busyAtArray.getJSONObject(0).getString("ended_at")
    // convert the string and get the time from it
    
    }
    

    I hope you got the general idea from this. This snippet can certainly be written in a better way.

提交回复
热议问题