1

尝试UILabel使用NSString. NSStringconsole作品上表现相同。

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (self.connectionData)
    {
        NSError *error;
        self.dict = [NSJSONSerialization JSONObjectWithData:self.connectionData options:kNilOptions error:&error];
        self.matchesArray = self.dict[@"matches"];

        NSString *title = [self.matchesArray valueForKey:@"title"];
        NSLog(@"NSString TITLE contains: %@", title);
        self.titleLabel.text = title;
    }
}

控制台输出:

2013-01-16 13:54:08.550 ZEITreisen[3168:c07] NSString TITLE contains: (
    "Mark und Dollar"
)
2013-01-16 13:54:08.552 ZEITreisen[3168:c07] -[__NSArrayI isEqualToString:]: unrecognized selector sent to instance 0xde93850
(lldb) 
4

3 回答 3

2

title不是NSString,是NSArray

所以

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (self.connectionData)
    {
        NSError *error;
        self.dict = [NSJSONSerialization JSONObjectWithData:self.connectionData options:kNilOptions error:&error];
        self.matchesArray = self.dict[@"matches"];

        NSArray *title = [self.matchesArray valueForKey:@"title"];
        NSLog(@"NSString TITLE contains: %@", title);
        self.titleLabel.text = [title lastObject];
    }
}
于 2013-01-16T13:01:38.793 回答
0

尝试 :

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (self.connectionData)
    {
        NSError *error;
        self.dict = [NSJSONSerialization JSONObjectWithData:self.connectionData options:kNilOptions error:&error];
        self.matchesArray = self.dict[@"matches"];

        NSString *title = [self.matchesArray valueForKey:@"title"];
        NSLog(@"NSString TITLE contains: %@", title);
        self.titleLabel.text = [NSString stringWithFormat:@"%@",[title objectAtIndex:0]];
    }
}
于 2013-01-16T13:03:18.903 回答
0

也许您存储在 self.matchesArray 中的值不是字符串

于 2013-01-16T13:05:36.017 回答