2011-12-14 54 views
0

我想从NSDictionary中检索一个值。不知道从NSDictionary中检索的值

下面是一个代码片段:

NSDictionary *metadataDict = [representation metadata]; 
NSLog(@"%@",metadataDict); 

“原始日期时间”是我想从以下输出检索值。

{ 
ColorModel = RGB; 
DPIHeight = 72; 
DPIWidth = 72; 
Depth = 8; 
Orientation = 6; 
PixelHeight = 1936; 
PixelWidth = 2592; 
"{Exif}" =  { 
    ApertureValue = "2.970854"; 
    ColorSpace = 1; 
    ComponentsConfiguration =   (
     1, 
     2, 
     3, 
     0 
    ); 
    DateTimeDigitized = "2011:09:28 09:35:36"; 
    DateTimeOriginal = "2011:09:28 09:35:36"; 
    ExifVersion =   (
     2, 
     2, 
     1 
    ); 
    ExposureMode = 0; 
    ExposureProgram = 2; 
    ExposureTime = "0.06666667"; 
    FNumber = "2.8"; 
    Flash = 24; 
    FlashPixVersion =   (
     1, 
     0 
    ); 
    FocalLength = "3.85"; 
    ISOSpeedRatings =   (
     320 
    ); 
    MeteringMode = 5; 
    PixelXDimension = 2592; 
    PixelYDimension = 1936; 
    SceneCaptureType = 0; 
    SensingMethod = 2; 
    Sharpness = 2; 
    ShutterSpeedValue = "3.9112"; 
    SubjectArea =   (
     1295, 
     967, 
     699, 
     696 
    ); 
    WhiteBalance = 0; 
}; 
"{GPS}" =  { 
    Latitude = "37.54216666666667"; 
    LatitudeRef = N; 
    Longitude = "126.95"; 
    LongitudeRef = E; 
    TimeStamp = "01:19:05.00"; 
}; 
"{TIFF}" =  { 
    DateTime = "2011:09:28 09:35:36"; 
    Make = Apple; 
    Model = "iPhone 4"; 
    Orientation = 6; 
    ResolutionUnit = 2; 
    Software = "4.3.5"; 
    XResolution = 72; 
    YResolution = 72; 
    "_YCbCrPositioning" = 1; 
}; 

}

我知道这是很长,但我想这三个,它仍然是行不通的。 NSLog(@“valueForKey%@”,[metadataDict valueForKey:@“DateTimeOriginal”]); NSLog(@“valueForKeyPath%@”,[metadataDict valueForKeyPath:@“DateTimeOriginal”]); NSLog(@“objectForKey%@”,[metadataDict objectForKey:@“DateTimeOriginal”]);

有谁知道NSDictionary中的数据类型是什么类型,以及如何检索它?

非常感谢。

以上项目链接: http://dl.dropbox.com/u/12439052/TheK2.zip

回答

4

你真正寻找的是

NSDictionary *exif = [metadataDict objectForKey:@"{Exif}"]; 
NSLog(@"DateTimeOriginal: %@", [exif objectForKey:@"DateTimeOriginal"]); 

如果你读了您的第一个日志的输出,你会看到你想要的关键其实是在另一个字典中有关键字"{Exif}"。此外,-objectForKey:是更好的方法来使用而不是-valueForKey:(后者是用于通用KVO,前者是真正的字典对象访问器)。

+0

它的工作原理!谢谢Kevin Ballard! :) –

0

试试这个:

NSString *DateTimeOriginal=[[metadataDict objectForKey:@"{Exif}"]objectForKey:@"DateTimeOriginal"]; 
0

在线路响应数值牢记

{ .......... } indicates dictionary. 
(............) indicates array. 
Dictionary always have key with it like somename = "value in it". 
Array has value seperated by comma like a , b , c ..... 
Now it is possible it may have array into dictionary like { SubjectArea = (1295,967,699,696);} and vice versa. 
相关问题