解析有效的JSON PHP时出现问题


Problems Parsing Valid JSON PHP

我尝试了各种方法来解析下面的json,但它对我不起作用。它返回空白。例如,我将如何检索SourceFile名称"example.jpg"或文件大小并将其存储为变量?谢谢

[
    {
        "SourceFile": "example.jpg",
        "ExifTool": {
            "ExifToolVersion": 9.04
        },
        "File": {
            "FileName": "example.jpg",
            "Directory": ".",
            "FileSize": "323 kB",
            "FileModifyDate": "2013:10:17 11:10:21-04:00",
            "FileAccessDate": "2013:12:10 11:47:49-05:00",
            "FilePermissions": "rwxrwxrwx",
            "FileType": "JPEG",
            "MIMEType": "image/jpeg",
            "ImageWidth": 1000,
            "ImageHeight": 658,
            "EncodingProcess": "Progressive DCT, Huffman coding",
            "BitsPerSample": 8,
            "ColorComponents": 3,
            "YCbCrSubSampling": "YCbCr4:4:4 (1 1)"
        },
        "JFIF": {
            "JFIFVersion": 1.02,
            "ResolutionUnit": "None",
            "XResolution": 100,
            "YResolution": 100
        },
        "Ducky": {
            "Quality": "95%"
        },
        "XMP": {
            "XMPToolkit": "Adobe XMP Core 4.2.2-c063 53.352624, 2008/07/30-18:12:18 ",
            "Make": "Canon",
            "Model": "Canon EOS 40D",
            "XResolution": 240,
            "YResolution": 240,
            "ResolutionUnit": "inches",
            "ExifVersion": "0221",
            "ExposureTime": "1/1000",
            "ShutterSpeedValue": "1/1000",
            "FNumber": 8,
            "ApertureValue": 8,
            "ExposureProgram": "Aperture-priority AE",
            "DateTimeOriginal": "2013:09:27 13:03:40.00+01:00",
            "DateTimeDigitized": "2013:09:27 13:03:40.00+01:00",
            "ExposureCompensation": "-2/3",
            "MaxApertureValue": 4,
            "SubjectDistance": "5.19 m",
            "MeteringMode": "Multi-segment",
            "FocalLength": "500.0 mm",
            "CustomRendered": "Normal",
            "ExposureMode": "Auto",
            "WhiteBalance": "Auto",
            "SceneCaptureType": "Standard",
            "FocalPlaneXResolution": 4438.35616438356,
            "FocalPlaneYResolution": 4445.96912521441,
            "FocalPlaneResolutionUnit": "inches",
            "ExifImageWidth": 3888,
            "ExifImageHeight": 2592,
            "ModifyDate": "2013:09:27 13:03:40.00+01:00",
            "CreateDate": "2013:09:27 13:03:40.00+01:00",
            "Rating": 0,
            "MetadataDate": "2013:09:27 13:03:40.00+01:00",
            "SerialNumber": 1130502837,
            "LensInfo": "500mm f/?",
            "Lens": "EF500mm f/4L IS USM",
            "LensID": 143,
            "ImageNumber": 0,
            "FlashCompensation": 0,
            "OwnerName": "Derek Lees WS66JU",
            "Firmware": "1.1.1",
            "Format": "image/tiff",
            "PreservedFileName": "IMG_8987.CR2",
            "SidecarForExtension": "CR2",
            "ColorMode": "RGB",
            "ISO": 400,
            "FlashFired": false,
            "FlashReturn": "No return detection",
            "FlashMode": "Off",
            "FlashFunction": false,
            "FlashRedEyeMode": false,
            "Creator": [
                "Derek Lees WS66JU",
                "Derek Lees"
            ],
            "Rights": "© Derek Lees 2013",
            "HistoryAction": "converted",
            "HistoryParameters": "from image/tiff to image/jpeg"
        },
        "APP14": {
            "DCTEncodeVersion": 100,
            "APP14Flags0": "[14], Encoded with Blend=1 downsampling",
            "APP14Flags1": "(none)",
            "ColorTransform": "YCbCr"
        },
        "Composite": {
            "Aperture": 8,
            "Flash": "Off, Did not fire",
            "ImageSize": "1000x658",
            "ScaleFactor35efl": 1.6,
            "ShutterSpeed": "1/1000",
            "CircleOfConfusion": "0.019 mm",
            "DOF": "0.03 m (5.18 - 5.20)",
            "FOV": "2.5 deg",
            "FocalLength35efl": "500.0 mm (35 mm equivalent: 809.4 mm)",
            "HyperfocalDistance": "1683.65 m",
            "LensID": "Canon EF 500mm f/4L IS",
            "LightValue": 14
        }
    }
]

由于您提到了PHP,PHP中的json_decode函数会将json解码为多级对象(或数组)。从那里,您可以使用foreach或直接命名数组/对象部分来获得所需的数据。