0

这可能看起来很基本,但我不明白。

我从字典中有以下数据。

要提取 ColorModel 我只是做object.ColorModel
这里没有问题或问题。

但是如何提取“{Exif}”?我无法输入对象。"{Exif}"

{

ColorModel = RGB;

DPIHeight = 72;

DPIWidth = 72;

Depth = 8;

Orientation = 1;

PixelHeight = 3000;

PixelWidth = 4000;

"{Exif}" =     {

    ApertureValue = "2.96875";

    ColorSpace = 1;

    ComponentsConfiguration =         (

        0,

        0,

        0,

        1

    );

    CompressedBitsPerPixel = 3;

    CustomRendered = 0;

    DateTimeDigitized = "2012:03:22 13:17:00";

    DateTimeOriginal = "2012:03:22 13:17:00";

    DigitalZoomRatio = 1;

    ExifVersion =         (

        2,

        2

    );

    ExposureBiasValue = 0;

    ExposureMode = 0;

    ExposureTime = "0.01666666753590107";

    FNumber = "2.799999952316284";

    Flash = 24;

    FlashPixVersion =         (

        1,

        0

    );

    FocalLength = 5;

    FocalPlaneResolutionUnit = 2;

    FocalPlaneXResolution = "16393.4453125";

    FocalPlaneYResolution = "16393.4453125";

    ISOSpeedRatings =         (

        200

    );

    MaxApertureValue = "2.96875";

    MeteringMode = 5;

    PixelXDimension = 4000;

    PixelYDimension = 3000;

    SceneCaptureType = 0;

    SensingMethod = 2;

    ShutterSpeedValue = "5.90625";

    WhiteBalance = 0;

};

"{TIFF}" =     {

    DateTime = "2012:03:26 21:00:45";

    HostComputer = "Mac OS X 10.7.3";

    Make = Canon;

    Model = "Canon PowerShot SD940 IS";

    Orientation = 1;

    ResolutionUnit = 2;

    Software = "QuickTime 7.7.1";

    XResolution = 72;

    YResolution = 72;

    "_YCbCrPositioning" = 2;

};

}

4

3 回答 3

2

您的代码不是有效的 javascript。这是使用冒号进行声明的正确形式,而不是使用等号和逗号来分隔多个属性,而不是分号:

var data = {
    ColorModel: "RGB",
    DPIHeight: 72,
    DPIWidth: 72,
    "{Exif}": {
        ApertureValue:"2.96875"
    }
}

var dpiHeight = data.DPIHeight;
var aperture = data["{EXIF}"].ApertureValue;

然后,要引用包含在 javascript 符号中不合法的字符的属性名称,您可以使用该["{EXIF}"]符号。

于 2012-08-18T19:47:32.600 回答
2

尝试对象["{Exif"}"];

No period. This will allow you to reference invalid JS names (like this case) or reserved words like "class" or "in".

于 2012-08-18T19:52:29.993 回答
1

将对象视为哈希表。所有对象属性都可以用作 JavaScript 中的哈希字符串。

var value = object["{Exif}"];
于 2012-08-18T19:46:58.073 回答