Reputation: 1635
I am attempting to call the khan academy api inside my iOS app. I am using the AFNetworking class to make the api call. Here is my code:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager GET:@"http://www.khanacademy.org//api/v1/topictree" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
[activityIndicator stopAnimating];
NSLog(@"no error");
for (NSString *key in [responseObject allKeys]) {
NSLog(@"%@", [responseObject objectForKey:key]);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error");
[activityIndicator stopAnimating];
NSLog(@"Error Khan: %@", [error localizedDescription]);
}];
When I visited http://www.khanacademy.org//api/v1/topictree it was a very long list. I have a hunch it may be the JSON parsing because I am only getting one NSDictionary. As you can see in the code above I used Fast Enumeration to view the values and the keys.
If that is the correct parse. I have no idea which keys to use to get a list of all the topics. Then when a user clicks on the topic I want to show a list of the video then I need to access the video download url specific to mp4. I could do it in the playlist list method however it has been deprecated.
The goal of this is to be able to view a list if topics followed by the topics videos followed by the video description then its downloadable url in mp4 format.
I have also been getting the error Error Khan:
The operation couldn’t be completed. (Cocoa error 3840.)
But some of the time it works.
All help is appreciated.
Thanks in advance,
Joel
Upvotes: 0
Views: 252
Reputation: 3457
that error code means JSON text did not start with array or object and option to allow fragments not set.
because response json from server is not a valid json for retireve array or object. Try using
NSJSONReadingAllowFragments
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options: NSJSONReadingAllowFragments error:&error];
NSLog(@"response: %@ error: %@", json, error);
Upvotes: 0