Search code examples
androidretrofittreemap

Issues with LinkedTreeMap object returned from RetroFit library


When i try to access the results with reviewdata.result.get("results") it expects an object and wont let me iterate through results =( ! I am looking for a way to get the resuluts node into a structure I can use. Any help is appreciated.

0 = {LinkedTreeMap$Node@3888} "page" -> "1.0"
1 = {LinkedTreeMap$Node@3889} "results" -> " size = 2"
2 = {LinkedTreeMap$Node@3890} "total_pages" -> "1.0"
3 = {LinkedTreeMap$Node@3891} "total_results" -> "2.0"  

Solution

  • Here is the complete code if anyone else runs into this issue when trying to work with gson Linked Tree Maps =D !

        LinkedTreeMap treemap = reviewdata.result;
        ArrayList<LinkedTreeMap> subtree = (ArrayList<LinkedTreeMap>) treemap.get("results");
        ArrayList<Review> reviews = new ArrayList<>();
    
        for(LinkedTreeMap map : subtree){
            Review review = new Review();
            review.setReviewID(map.get("id").toString());
            review.setAuthor(map.get("author").toString());
            review.setContent(map.get("content").toString());
            review.setURL(map.get("url").toString());
            reviews.add(review);
        }
    
        return  reviews;