2013-12-10 3 views
1

다음 json을 구문 분석하기 위해 다양한 방법을 시도했지만 나에게 도움이되지 못했습니다. 빈칸으로 돌아갑니다. 예를 들어 어떻게 SourceFile 이름 "example.jpg"또는 파일 크기를 변수로 검색하고 저장합니까? 감사!유효한 JSON 구문 분석 문제 PHP

[ 
    { 
     "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 
     } 
    } 
] 
+1

[json_decode()] (http://php.net/json_decode)를 이미 시도했다고 가정합니다. – echochamber

+0

@echochamber 예, 나는 그것을 시도했습니다 : $ json = json_encode ($ exif, true); echo $ json [ 'FileSize']; – user2600095

+0

json_last_error_msg()에서 객체 특성 이름 구분 기호 ':'가 예상됩니다. 나는''Rights "주위에 문제가 있다고 생각한다 :''© Derek Lees 2013" – Phil

답변

0

는 PHP 언급 때문에 PHP의 json_decode 함수 다단계 객체 (또는 어레이)에 JSON을 디코딩한다. 여기서 foreach 또는 배열/객체 섹션의 직접 명명을 사용하여 원하는 데이터를 얻을 수 있습니다.

+0

위버 나는 이것을 사용해 보았습니다 ... 아무 소용이 없습니다. – user2600095

+0

json_decode로 변수를 빌드 한 후 print_r 변수를 사용하면 어떻게됩니까? Array() 1을 얻나요? –

+0

아, 배열 구문 대신 객체 구문을 사용하십시오. 따라서 $ json [ 'FileSize'] 대신 $ json-> File-> FileSize를 사용하여 얻은 결과를 확인하십시오. –