I’m iOS Beginner, and I have some troubles with coding.
By sending ASIHTTPRequest:
NSURL *url = [NSURL URLWithString:@"http://search.twitter.com/search.json?geocode=37.781157,-122.398720,25km"];
I receive data like this:
{
"created_at" = "Fri, 25 Jan 2013 17:48:29 +0000";
"from_user" = "ZacHWallS_SBI";
"from_user_id" = 252712138;
"from_user_id_str" = 252712138;
"from_user_name" = "ZACH WALLS";
geo = "<null>";
id = 294864332490162176;
"id_str" = 294864332490162176;
"in_reply_to_status_id" = 294861687004225537;
"in_reply_to_status_id_str" = 294861687004225537;
"iso_language_code" = en;
location = "BAY AREA CALIFORNIA";
metadata = {
"result_type" = recent;
};
"profile_image_url" = "http://a0.twimg.com/profile_images/3029389178/e3567459d147bc5d0a10f3c797b477aa_normal.png";
"profile_image_url_https" = "https://si0.twimg.com/profile_images/3029389178/e3567459d147bc5d0a10f3c797b477aa_normal.png";
source = "<a href="http://twitter.com/#!/download/ipad">Twitter for iPad</a>";
text = "@LilTioSBi yee ima slide through prolly";
"to_user" = LilTioSBi;
"to_user_id" = 35629694;
"to_user_id_str" = 35629694;
"to_user_name" = "Nevin Tio";
},
Next I do this:
-(void) requestFinished: (ASIHTTPRequest *) request {
NSString *theJSON = [request responseString];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableArray *jsonDictionary = [parser objectWithString:theJSON];
//NSLog(@"\n\n%@", jsonDictionary);
NSMutableArray *userName = [userinfo objectForKey:@"from_user"];
NSLog(@"\n\n\n%@",userName);
I need to capture “from_user”.
Then run, and compiler says: [__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x755bbc0…
How do it correctly?
So, I’ll be begin by clarifying something, which is that it’s actually the runtime that is giving you the “[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x755bbc0” error.
Let’s break it down:
__NSArrayMsounds suspiciously likeNSArray(NSArrayis technically something called a class cluster, meaning you won’t always see exactlyNSArrayin practice, just something that works like one).-objectForKey:is a method onNSDictionarySo, we’re calling a method on an array that we think is a dictionary (calling a method = sending a message, or “selector” in ObjC parlance).
It seems like you’ve omitted some of your code, but if you just passed the value from something like:
You would end up with an array of tweets. You then need to grab an item from that array to get at its
from_userkey.