【发布时间】:2011-08-25 23:25:47
【问题描述】:
-(void)messageSend:(NSString *)message;
{
NSLog(@"messageSend");
urlString = [[NSString alloc] initWithFormat:@"http://someaddress/message/send?from=%@&msg=%@&latitude=0&longitude=0",appDelegate.userName,message];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:urlString]];
NSLog(@"Dictionary response");
if ([dictionary count] > 0)
{
if ([[dictionary objectForKey:@"send"] isEqualToString:@"OK"] )
{
NSLog(@"envio de mensagem de %@ Ok: %@",appDelegate.userName,message);
}
}
[urlString release];
[dictionary release];
}
给出-[__NSArrayM getObjects:andKeys:]: unrecognized selector sent to instance 的错误。经过NSLogs 的一些测试,这条线
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithDictionary:[self request:urlString]];
是罪魁祸首,女巫正在调用这个方法:
-(NSDictionary *)request:(NSString *)requestString
{
url =[[NSURL alloc] initWithString:requestString];
request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
error = [[NSError alloc] init];
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
[responseData retain];
NSString *tempString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSMutableDictionary *tempDict= [[[NSMutableDictionary alloc] init] autorelease];
if (request)
{
Parser *parser = [[Parser alloc] init];
tempDict = [parser readXMLString:tempString];
for (id key in tempDict)
{
NSLog(@"%@ is %@",key,[tempDict objectForKey:key]);
}
}
[url release];
[error release];
[responseData release];
[tempString release];
return tempDict;
}
当消息的字符串有空格时会发生这种情况。 但以前没有发生过。
【问题讨论】:
-
readXMLString总是返回字典吗? -
很明显,readXMLString 没有返回 NSDictionary。
标签: objective-c ios xcode nsstring nsdictionary