API: Is this a bug or feature?
komy
Registered Users Posts: 19 Big grins
Hi,
I am using the 1.2.0 JSON API to fetch a list of subcategories for a given category using Javascript. However, the data structure returned from the API does not look quite right to me. Here is what is returning from the API.
If what the current API returns is in a correct structure, how should I loop through each subcategory?
Thanks,
Kevin
I am using the 1.2.0 JSON API to fetch a list of subcategories for a given category using Javascript. However, the data structure returned from the API does not look quite right to me. Here is what is returning from the API.
{"stat":"ok", "method":"smugmug.subcategories.get", "SubCategories":{ "311625":{"id":311625,"Title":"Subcategory 1"}, "313457":{"id":313457,"Title":"Subcategory 2"} } }I would expect the API retuning subcategories in an array structure like:
{"stat":"ok", "method":"smugmug.subcategories.get", "SubCategories":[ {"id":311625, "Title":"Subcategory 1"}, {"id":313457, "Title":"Subcategory 2"} ] }
If what the current API returns is in a correct structure, how should I loop through each subcategory?
Thanks,
Kevin
0
Comments
That's the way we decided to do for all methods that return sets of data.
The results can be easily iterated using the for command like below...
where x is the variable that the JSON structure was assigned to.
The advantage of this method is that if you know the SubCategory ID that you want, you don't need to iterate the array to find the index, it can be accessed directly using the SubCategory ID.
eg. SubCategories.311625.Title
I hope this makes sense.
Cheers,
David
SmugMug API Developer
My Photos
Kevin