Skip to content

Couldn't parse twitter API as returned from URL : https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=a&count=2 #145

Closed
MedmaGit opened this Issue Sep 7, 2012 · 5 comments

2 participants

@MedmaGit
MedmaGit commented Sep 7, 2012

Parser have been working soo good to me since this long as had helped me parsing google, facebook and many other returned JSON. But now it have an issue in JSON the returned from above twitter URL: it is like:

https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=a&count=1

[{"created_at":"Thu Sep 06 23:02:39 +0000 2012","id":243846704393248768,"id_str":"243846704393248768","text":"@sfgirl I remember during Brooklyn Beta we checked it out for $650+ or so.","source":"web","truncated":false,"in_reply_to_status_id":243803382802960384,"in_reply_to_status_id_str":"243803382802960384","in_reply_to_user_id":10249752,"in_reply_to_user_id_str":"10249752","in_reply_to_screen_name":"sfgirl","user":{"id":940631,"id_str":"940631","name":"Andrei Zmievski","screen_name":"a","location":"San Francisco, CA","url":"http:\/\/zmievski.org\/","description":"Coder, photographer, beer judge and brewer, Russian, and San Franciscan. Software architect at @AppDynamics.","protected":false,"followers_count":52376,"friends_count":236,"listed_count":994,"created_at":"Sun Mar 11 18:05:57 +0000 2007","favourites_count":450,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11886,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"170F00","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/2909595\/AZ-twitter.gif","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/2909595\/AZ-twitter.gif","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1843828229\/headshot_bw_m_copy_normal.jpg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1843828229\/headshot_bw_m_copy_normal.jpg","profile_link_color":"A04521","profile_sidebar_border_color":"E6AA51","profile_sidebar_fill_color":"E6AA51","profile_text_color":"170F00","profile_use_background_image":true,"show_all_inline_media":true,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"sfgirl","name":"Melanie","id":10249752,"id_str":"10249752","indices":[0,7]}]},"favorited":false,"retweeted":false}]

And while trying to parse it come up with following Exception:

2012-09-07 11:11:06.403 XYZ[3179:930b] -[NSArrayM setObject:forKey:]: unrecognized selector sent to instance 0x65f43a0
2012-09-07 11:11:06.404 XYZ[3179:930b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM setObject:forKey:]: unrecognized selector sent to instance 0x65f43a0'
*** Call stack at first throw:
(
0 CoreFoundation 0x0157ebe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x013735c2 objc_exception_throw + 47
2 CoreFoundation 0x015806fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x014f0366 ___forwarding_
+ 966
4 CoreFoundation 0x014eff22 CF_forwarding_prep_0 + 50
5 XYZ 0x0003445f -[Support requestDataInBackground:] + 592
6 Foundation 0x000c4d4c -[NSThread main] + 81
7 Foundation 0x000c4cd8 __NSThread__main_
+ 1387
8 libSystem.host.dylib 0x01c617fd _pthread_start + 345
9 libSystem.host.dylib 0x01c61682 thread_start + 34
)
terminate called after throwing an instance of 'NSException'

@stig
Owner
stig commented Sep 7, 2012

It doesn't look like that exception is coming from SBJson. I just tried to parse that JSON using the "DisplayPretty" reformatting tool that ships in the SBJson source tree, and it seems to work just fine. If you don't find the issue, could you post your code?

@MedmaGit
MedmaGit commented Sep 7, 2012

Here is the code that i am using:

url = https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=a&count=2

  • (void) requestDataInBackground : (NSString ) url{
    NSLog(@"requested");
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSString *unescapedString = [NSString stringWithString:url];
    NSString
    escapedUrlString = [unescapedString stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];

    NSURL *reqURL = [[NSURL alloc] initWithString:escapedUrlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:reqURL];

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

    //To print response in string format
    NSString *responseString = [[[NSString alloc] initWithData:response
    encoding:NSUTF8StringEncoding] autorelease];
    if(responseString != NULL)
    NSLog(@"\n\n RECIEVED(response) JSON: \n %@\n\n",responseString);

    SBJSON *parser = [[SBJSON alloc] init];
    NSMutableDictionary *_data = [((NSDictionary *) [parser objectWithString:responseString error:nil]) mutableCopy];
    [_data setObject:url forKey:kKeyRequestedURL];
    NSLog(@"_data = %@", _data);

    [self performSelectorOnMainThread:@selector(requestCompletedWithDictionary:)
    withObject:_data
    waitUntilDone:NO];

    [pool release];
    }

@stig
Owner
stig commented Sep 7, 2012
@MedmaGit
@stig
Owner
stig commented Sep 7, 2012
@stig stig closed this Dec 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.