Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:44:06+00:00 2026-06-08T05:44:06+00:00

I working with the Dropbox API and I would like to get the folders

  • 0

I working with the Dropbox API and I would like to get the folders and paths from a json object. However I am having problems as there is an undermined number of child nodes. How would I go about parsing something like this?

EDIT

The JSONObject represents a directory. The top level folder is represented by a json object. Within that object are the sub-folders. Each of them has there down JSONobject, within each of these jsonobject there is an array which represent the subfolders of the subfolder. So I don’t know the complete structure of the json

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:44:08+00:00Added an answer on June 8, 2026 at 5:44 am

    I just had this very same problem, I wrote a class with a recursive algorithm that goes through and searches for a specific id.. seems to work alright, feel free to give it a try!

    import java.util.ArrayList;
    import java.util.List;
    
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
    
    public class JsonReference {
        Object data;
    
        public JsonReference(String buildFromString){
            try {
                data = new JSONObject(buildFromString);
            } catch (JSONException e) {
                e.printStackTrace();
            }
    
            if(data == null){
                try {
                    data = new JSONArray(buildFromString);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    
        public Object getAbstractJsonObject(){
            return data;
        }
    
        public List<String> parseForData(String data,boolean removeDuplicates){
            Traverser valFinder = new Traverser(0);
            valFinder.setValues(data, removeDuplicates);
            valFinder.traverseForStringValue(this.data);
            return valFinder.foundInstances;
        }
    
        class Traverser{
            List<String> foundInstances = new ArrayList<String>();
            String value;
            boolean removeDuplicates;
    
            public Traverser(int type){
    
            }
    
            public void setValues(String value,boolean removeDuplicates){
                this.value = value;
                this.removeDuplicates = removeDuplicates;
            }
    
            public void traverseForStringValue(Object root){
    
                if(root == null){
                    return;
                }
                else if(root instanceof JSONObject){
                    JSONObject self = (JSONObject)root;
    
                    //if the key exists in this object.. save it!
                    if(self.has(value)){
                        try {
                            if(!removeDuplicates || notRepeat(self.getString(value)))
                                foundInstances.add(self.getString(value));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        return;
                    }
    
                    //otherwise, see if you can dive deeper..
                    JSONArray names = self.names();
                    for(int i=0;i<names.length();i++){
                        String temp = null;
                        try{
                            temp = names.getString(i);
                        }
                        catch(JSONException e){
                            e.printStackTrace();
                        }
                        if(temp != null){
                            try {
                                if(self.get(temp) instanceof JSONObject || self.get(temp) instanceof JSONArray)
                                    traverseForStringValue(self.get(temp));
                                else if(self.get(temp) instanceof String){
                                    if(!removeDuplicates || notRepeat(self.getString(value)))
                                        foundInstances.add(self.getString(value));
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
    
                }
                else if(root instanceof JSONArray){
                    JSONArray self = (JSONArray)root;
    
                    //iterate through the array..
                    for(int i=0;i<self.length();i++){
                        Object temp = null;
                        try {
                            temp = self.get(i);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
    
                        if(temp != null && temp != JSONObject.NULL){
    
                            if(temp instanceof JSONObject || temp instanceof JSONArray)
                                traverseForStringValue(temp);
                            else if(temp instanceof String && ((String)temp).contains(value)){
                                try {
                                    if(!removeDuplicates || notRepeat(self.getString(i)))
                                        foundInstances.add(self.getString(i));
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
    
                        }
                    }
                }
            }
    
            private boolean notRepeat(String s){
                for(String item : foundInstances){
                    if(item.equals(s))
                        return false;
                }
                return true;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a script that downloads a file from Dropbox, supposed to
I am working on a dropbox like system and I am wondering how the
Need help here. i managed to get the drinkName and categories working. http://dl.dropbox.com/u/418769/2.png but
I've been working with the Dropbox API as of late, and have run into
I'm trying to get site in a dropbox working mainly to figure out how
I am working on Dropbox. I see the documentation. This is my code to
Working with an undisclosed API, I found a function that can set the number
Working with H2 I get this error when I try to write a row
Working on the problems on Project Euler to try to learn Clojure. I'm on
Working with MS Access for the first time and coming across a few problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.