I have been trying to get a twitter search to work using NSJSONSerialization to parse the query results. I originally used a tutorial on accessing Twitter data using an SLRequest, but I've found that in doing this I need the results to update a property in order to save them. I want the fetching to be a class method, so I'm avoiding using properties. The issue I'm running into is a bit weird and I'm not sure why it would be happening. Basically I can get the fetch with [NSJSONSerialization JSONObjectWithData: ...] reliably -- except for one key:value pair in the dictionary, the results. The value for the key "results" is returning as ( ), and is type __NSArrayM. I can see that the URL I am sending to fetch the data is correct, and that the rest of the information in the parsed dictionary is correct. I'm not sure why this would be occurring though.
Here is an example GET request: https://search.twitter.com/search.json?q=tech%20filter%3Alinks%20lang%3Aen&src=typd&rpp=1&include_entities=true
If you go to that page, you can see that the "results" key has a value associated with it, and it should be an array. In my parsed version, though, I have an empty array:
fetchResults = {
"completed_in" = "0.045";
"max_id" = 309208532929101825;
"max_id_str" = 309208532929101825;
page = 1;
query = "tech%2520filter%253Alinks%2520lang%253Aen";
"refresh_url" = "?since_id=309208532929101825&q=tech%2520filter%253Alinks%2520lang%253Aen&include_entities=1";
results = (
);
"results_per_page" = 1;
"since_id" = 0;
"since_id_str" = 0;
}
Is there a reason why this may be occurring? I've put in my code for the JSON parsing below.
+(NSArray *)fetchTweetsForSearchContent:(NSString *)searchContent
{
NSString *requestURL = [[TwitterFetcherrequestURLWithSearchContent:searchContent] absoluteString];
NSLog(@"URL: %@",requestURL);
NSString *query = [requestURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *jsonData = [[NSStringstringWithContentsOfURL:[NSURLURLWithString:query] encoding:NSUTF8StringEncodingerror:nil] dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *fetchResults = jsonData ? [NSJSONSerializationJSONObjectWithData:jsonData options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaveserror:&error] : nil;
if (error) NSLog(@"[%@ %@] JSON error: %@", NSStringFromClass([selfclass]), NSStringFromSelector(_cmd), error.localizedDescription);
NSLog(@"%@", fetchResults);
return [fetchResults objectForKey:@"results"];
}