foursquare / FSNetworking

foursquare iOS networking library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arrayFromJSONWithError for NSData category

ahmetb opened this issue · comments

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?

Thanks.

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?

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.

Thanks!