You are receiving an NSString
object from [jsonDictionary objectForKey:@"html"];
Regardless how you actually declared the receiving variable, NSData
in this case, it will be assigned what the method actually returns. And that is an NSString
in this case.
In general it is advisable to receive the data in a variable of type id first and then check its class using isKindOfClass
and then go from there.
NSData *htmlData;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
id nextElement = [jsonDictionary objectForKey:@"html"];
if (id isKindOfClass:[NSString class]) {
htmlData = [(NSString*)id dataUsingEncoding:NSUTF8StringEncoding];
} else {
// Deal with the error or cover other classes accordingly
}
TFHpple *parser = [TFHpple hppleWithHTMLData:htmlData];
NSArray *tableRows = [mainParser searchWithXPathQuery:@"//tr/td"]