Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

arrayFromJSONWithError for NSData category #5

ahmetb opened this Issue Dec 16, 2012 · 2 comments


None yet
2 participants

ahmetb commented Dec 16, 2012

Along with this method:

// convenience method to ensure that top-level json object is a dictionary
- (id)dictionaryFromJSONWithError:(NSError **)error; // error pointer must not be nil

it would be really great if you provide arrayFromJSONWithError that internally calls this one and returns NSArray of NSDictionary instances from JSON, that would be good. I guess you also have such a need in 4sq API. Am I missing an obvious workaround?



gwk commented Dec 17, 2012

Thank you for the suggestion; have added a method named arrayFromJSONWithError: in my personal fork at https://github.com/gwk/FSNetworking. I will issue a pull request shortly.

However, you should note that both of these functions exist for the purpose of type safety: they parse the JSON and then check that the root object is of the expected type. Which one you use depends on what root type your API returns; every API I have ever seen (including the foursquare API) uses a dictionary as a root object, but arrays are certainly possible.

Your question suggests that there might be a conceptual misunderstanding; does this help clear things up?

ahmetb commented Dec 17, 2012

Hi George. Thanks for quick response. We are on the same page about why these methods exist.

However, I think not all APIs provide dict as top level json objects in response. Well, most of them do so but there are certainly exceptions like some old-fashioned ones like Twitter: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

I also created the same method with exact same contents for a quick workaround and it worked. Should be god to go then. Hopefully it gets merged, soon.


@ahmetb ahmetb closed this Jun 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment