FourSquare API: How to get specific categories using the top level category id?

629 views Asked by At

I'm currently using the endpoint below

https://api.foursquare.com/v2/venues/categories?client_id=****&client_secret=****&v=20161222&m=foursquare

and then saving the results as the following

JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONArray("categories");

This is giving me a list of all of the categories however I'm specifically looking for those in the food category.I want to filter out the categories using the food id which is 4d4b7105d754a06374d81259. Is there any way to do this from the JSONArray?

1

There are 1 answers

0
kulsoompatel On BEST ANSWER

The code below depicts how to get to a specific category. Go through each category ID until the match is found.

  try {
                JSONObject jsonObject = new JSONObject(result);
                if (jsonObject.has("response")) {

                    if (jsonObject.getJSONObject("response").has("categories")) {
                        JSONArray jsonArray = jsonObject.getJSONObject("response").getJSONArray("categories");


                        for (int i = 0; i < jsonArray.length(); i++) {

                            JSONObject eachCategory = jsonArray.getJSONObject(i);
                            eachID = eachCategory.getString("id");

                            //This is the food ID

                            if (eachID.equals("4d4b7105d754a06374d81259")) {