Retrival of folder list not working
IKEngine.h: foldersWithUserInfo: not working Retrival of folder list fails in IKDeserializer.m Line 81. if (![JSONArray isKindOfClass:[NSArray class]]) { // Invalid JSON return nil; } always branches to "return nil".
This part is never reached: } else if ([type isEqualToString:@"folder"]) { // Create folder object IKFolder *folder = [[IKFolder alloc] init];
folder.folderID = [[self _normalizedObjectForKey:@"folder_id" inDictionary:dict] integerValue];
folder.title = [self _normalizedObjectForKey:@"title" inDictionary:dict];
folder.syncToMobile = [[self _normalizedObjectForKey:@"sync_to_mobile" inDictionary:dict] boolValue];
folder.position = [[self _normalizedObjectForKey:@"position" inDictionary:dict] unsignedIntegerValue];
[result addObject:folder];
}
Although the class actually is NSArray, isKindOfClass: returns false (lldb) po JSONArray (NSArray *) $1 = 0x0000000114b6e4f0 { 1 = { "folder_id" = 1014091; position = 1302224455; "sync_to_mobile" = 1; title = Misc; type = folder; }; 2 = { "folder_id" = 1015059; position = 1302276097; "sync_to_mobile" = 1; title = Test; type = folder; }; }
I wasn't able to reproduce this but I added JKArray and JKDictionary as valid classes in commit 9cb1929f41b62e650e75d24df77fb1c23ac53c13.
Can you confirm that this solves the issue?
No, sorry, the problem persists. Very strange. I'm going to reinstall the developer tools. Maybe I have messed up something here. I will let you know if this solves the issue. Which SDK Version are you using?
I'm using the included Test build target with the Mac OS 10.6 SDK to test it. Do you use iOS?
No, using 10.6 SDK on Mac. Problem was that [JSONString objectFromJSONString] not always returns an array. At least this is the case here. Are you using the latest JSONKit?
I made it working like this. This creates an array in case objectFromJSONString returns a dictionary.
+ (id)objectFromJSONString:(NSString *)JSONString {
if (!JSONString) {
return nil;
}
// Parse JSON
id JSONObject = [JSONString objectFromJSONString];
NSMutableArray *JSONArray;
if ([JSONObject isKindOfClass:[NSDictionary class]]) {
// Create array with all dictionary entries
JSONArray = [NSMutableArray array];
NSArray *allKeys = [JSONObject allKeys];
for (NSString *aKey in allKeys) {
[JSONArray addObject:[JSONObject valueForKey:aKey]];
}
}
else if ([JSONObject isKindOfClass:[NSArray class]]){
// Already is an array, just pass
JSONArray = [NSMutableArray arrayWithArray:JSONObject];
}
else {
// Invalid JSON
return nil;
}
NSMutableArray *result = [NSMutableArray array];
for (NSDictionary *dict in JSONArray) {
// Get type
NSString *type = [dict objectForKey:@"type"];
I did test this only with these methods:
[[IKEngine alloc] initWithDelegate:sharedInstapaperDataManager];
[iKEngine bookmarksWithUserInfo:nil];
[iKEngine foldersWithUserInfo:nil];
I will test the other methods as soon as I get there. If you don't mind I am going to fork your repo so that you can see what I'm doing.
That's very weird. As long as the Instapaper API returns an array, JSONKit should do the same. Can you post the server response you get here? Charles might come in handy to do this or you can simply NSLog the response string.