本文介绍了如何解析Haskell中的Exiftool JSON输出示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解任何文档。有人可以提供一个例子,说明如何使用Haskell模块 Text.JSON 来解析以下缩短的 exiftool 输出。使用命令 exiftool -G -j 生成数据。

  [{
SourceFile:DSC00690.JPG,
ExifTool:ExifToolVersion:7.82,
File:FileName:DSC00690.JPG,
Composite:LightValue:11.6
},
{
SourceFile:DSC00693.JPG,
ExifTool:ExifToolVersion:7.82,
File:FileName:DSC00693.JPG,
EXIF:Compression:JPEG(旧式),
EXIF:ThumbnailLength:4817,
Composite:LightValue:13.0
},
{
SourceFile:DSC00694.JPG,
ExifTool:ExifToolVersion:7.82,
File: FileName:DSC00694.JPG,
Composite:LightValue:3.7
}]


(假设你的数据是在text.json中):

  Prelude Text.JSON> s<  -  readFiletest.json
Prelude Text.JSON> decode s :: Result JSValue
Ok(JSArray [JSObject(JSONObject {fromJSObject = [(SourceFile,JSString(JSONString {fromJSString =DSC00690.JPG})),(ExifTool:ExifToolVersion,JSRational False (391%50)),(File:FileName,JSString(JSONString {fromJSString =DSC00690.JPG})),(Composite:LightValue,JSRational False(58%5))]}),JSObject JSONObject {fromJSObject = [(SourceFile,JSString(JSONString {fromJSString =DSC00693.JPG})),(ExifTool:ExifToolVersion,JSRational False(391%50)),(File:FileName JSONString {fromJSString =DSC00693.JPG})),(EXIF:Compression,JSString(JSONString {fromJSString =JPEG(old-style)})),(EXIF:ThumbnailLength,JSRational False(4817% 1)),(Composite:LightValue,JSRational False(13%1))]}),JSObject(JSONObject {fromJSObject = [(SourceFile,JSString(JSONString {fromJSString =DSC00694.JPG}))), (ExifTool:ExifToolVersion,JSRational False(391%50)),(File:FileName,JSString(JSONString {fromJSString =DSC00694.JPG})),(Compo网站:LightValue,JSRational False(37%10))]})])

你是一个通用的json Haskell数据类型。

下一步将为你的数据定义一个自定义的Haskell数据类型,并为它写一个JSON实例,在上面的JSValue和你的类型之间。


I can't make sense of any of the documentation. Can someone please provide an example of how I can parse the following shortened exiftool output using the Haskell module Text.JSON? The data is generating using the command exiftool -G -j <files.jpg>.

[{
  "SourceFile": "DSC00690.JPG",
  "ExifTool:ExifToolVersion": 7.82,
  "File:FileName": "DSC00690.JPG",
  "Composite:LightValue": 11.6
},
{
  "SourceFile": "DSC00693.JPG",
  "ExifTool:ExifToolVersion": 7.82,
  "File:FileName": "DSC00693.JPG",
  "EXIF:Compression": "JPEG (old-style)",
  "EXIF:ThumbnailLength": 4817,
  "Composite:LightValue": 13.0
},
{
  "SourceFile": "DSC00694.JPG",
  "ExifTool:ExifToolVersion": 7.82,
  "File:FileName": "DSC00694.JPG",
  "Composite:LightValue": 3.7
}]
解决方案

Well, the easiest way is to get back a JSValue from the json package, like so (assuming your data is in text.json):

Prelude Text.JSON> s <- readFile "test.json"
Prelude Text.JSON> decode s :: Result JSValue
Ok (JSArray [JSObject (JSONObject {fromJSObject = [("SourceFile",JSString (JSONString {fromJSString = "DSC00690.JPG"})),("ExifTool:ExifToolVersion",JSRational False (391 % 50)),("File:FileName",JSString (JSONString {fromJSString = "DSC00690.JPG"})),("Composite:LightValue",JSRational False (58 % 5))]}),JSObject (JSONObject {fromJSObject = [("SourceFile",JSString (JSONString {fromJSString = "DSC00693.JPG"})),("ExifTool:ExifToolVersion",JSRational False (391 % 50)),("File:FileName",JSString (JSONString {fromJSString = "DSC00693.JPG"})),("EXIF:Compression",JSString (JSONString {fromJSString = "JPEG (old-style)"})),("EXIF:ThumbnailLength",JSRational False (4817 % 1)),("Composite:LightValue",JSRational False (13 % 1))]}),JSObject (JSONObject {fromJSObject = [("SourceFile",JSString (JSONString {fromJSString = "DSC00694.JPG"})),("ExifTool:ExifToolVersion",JSRational False (391 % 50)),("File:FileName",JSString (JSONString {fromJSString = "DSC00694.JPG"})),("Composite:LightValue",JSRational False (37 % 10))]})])

this just gives you a generic json Haskell data type.

The next step will be to define a custom Haskell data type for your data, and write an instance of JSON for that, that converts between JSValue's as above, and your type.

这篇关于如何解析Haskell中的Exiftool JSON输出示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:28