不确定从 NSDictionary 检索的值

发布于 2024-12-21 03:52:37 字数 2078 浏览 1 评论 0原文

我想从 NSDictionary 中检索一个值。

这是代码片段:

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

“DateTimeOriginal”是我想从以下输出中检索的值。

{
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

I want to retrive a value from a NSDictionary.

Here is a snippet of code:

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

"DateTimeOriginal" is the value I want to retrieve from the following output.

{
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;
};

}

I know it's long but I tried these three and it still would not work.

NSLog(@"valueForKey %@", [metadataDict valueForKey:@"DateTimeOriginal"]);
NSLog(@"valueForKeyPath %@", [metadataDict valueForKeyPath:@"DateTimeOriginal"]);
NSLog(@"objectForKey %@", [metadataDict objectForKey:@"DateTimeOriginal"]);

Does anyone know what kind of datatype is in the NSDictionary and how I can retrieve it?

Thanks much.

Above project link:
http://dl.dropbox.com/u/12439052/TheK2.zip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相对绾红妆 2024-12-28 03:52:37

您真正要寻找的是,

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

如果您阅读第一个日志的输出,您会发现您想要的键实际上位于另一个具有键 "{Exif}" 的字典中。另外,-objectForKey: 是比 -valueForKey: 更好的方法(后者用于通用 KVO,前者是真正的字典对象访问器)。

What you're really looking for is

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

If you read the output from your first log, you'll see that the key you want is actually inside another dictionary which has the key "{Exif}". Also, -objectForKey: is the better method here to use rather than -valueForKey: (the latter is for generic KVO, the former is the real dictionary object accessor).

假面具 2024-12-28 03:52:37

试试这个:

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

Try this one:

NSString *DateTimeOriginal=[[metadataDict objectForKey:@"{Exif}"]objectForKey:@"DateTimeOriginal"];
笨笨の傻瓜 2024-12-28 03:52:37

在响应期间牢记线路值

{ .......... } 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.

During Response Value of lines keep in mind

{ .......... } 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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文