我在正确访问从Flickr数据(flickr.photosets.getPhotos调用)构建的NSDictionary时遇到问题。它不仅仅显示描述标记的内容,而是读取描述标记...以及一些不必要的数据和引号。
例如:
NSLog (@"Item description readout: %@", itemDescriptionPre);
产生这种回应:
Item description readout: {
"_content" = "This is a caption from a photo drawn through Flickr";
}
我试图用这个
修改NSStringNSString *descripTruncated = [itemDescriptionPre substringFromIndex:17];
但它并没有在运行时导致崩溃。它也没有解决项目末尾的项目。我很抱歉,因为NSString修改似乎在这里有很多讨论,但我找不到反映我的情况。
以下是我的代码的更多上下文:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Storing incoming data");
NSDictionary *results = [jsonString JSONValue];
NSLog(@"Building NSDictionary.");
NSArray *photos = [[results objectForKey:@"photoset"] objectForKey:@"photo"];
NSLog(@"Building array from dictionary.");
// Loop through each entry in the dictionary...
for (NSDictionary *photo in photos)
{
NSString *title = [photo objectForKey:@"title"];
NSString *description = [photo objectForKey:@"description"];
[photoTitles addObject:title];
[photoDescriptions addObject:description];
}
NSLog(@"Nicer display for results: %@ First image title: %@ First image description: %@", results, [photoTitles objectAtIndex:0], [photoDescriptions objectAtIndex:0]);
[self updateDisplay];
}
-(void) updateDisplay{
NSString *capTitle = [[photoTitles objectAtIndex:0] uppercaseString];
photoTitleDisplay.text = capTitle;
NSString *itemDescriptionPre = [photoDescriptions objectAtIndex:0];
NSLog (@"Item description readout: %@", itemDescriptionPre);
}
答案 0 :(得分:0)
itemDescriptionPre
实际上是NSDictionary
。这应该有效:
NSDictionary *itemDescriptionPre = [photoDescriptions objectAtIndex:0];
NSString *itemDescription = [itemDescriptionPre objectForKey:@"_content"];