- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这样的圆形光学器件
import io.circe.parser._
import io.circe.optics._
import io.circe.optics.JsonPath._
val json = parse("""{"response": {"person": {"firstname": "foo", "lastname":"bar"}}}""").right.get
现在我想从这个 json 中以字符串形式提取整个人对象......
val p = root.response.person.string
然后将它解码成一个类
case class Person(firstname: String, lastname: String)
decode[Person](p.getOption(json).get)
但它不起作用,因为 root.response.person.string
返回 null。我认为它只适用于实际的字符串和整数列。
那么可以使用 circe optics 提取整个 json 部分(例如 json 中的 person 对象)吗?然后该部分被解码为案例类?
最佳答案
这样就搞定了。无需获取中间的字符串,只需使用 Json
object Some extends App {
import io.circe.optics.JsonPath._
import io.circe.parser._
import io.circe._
import io.circe.generic.semiauto._
val json = parse("""{"response": {"person": {"firstname": "foo", "lastname":"bar"}}}""").right.get
// this is just a lense to the person, not the person yet
val personJsonPath = root.response.person.json
case class Person(firstname: String, lastname: String)
implicit val personDecoder: Decoder[Person] = deriveDecoder[Person]
val maybePerson = personJsonPath
// here you get the person out
.getOption(json)
// transforming json directly to case class, error handling should not be done like this ;)
.map(_.as[Person].fold(throw _, identity))
println(maybePerson)
}
关于scala - 如何一起使用 Circe Optics 和 Decode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50034649/
我有一系列固定长度向量: data family Vector (n :: Nat) a data instance Vector 2 a = Vector2 a a data instance Ve
如何设置 Arrow 依赖项才能使 @optics 注释真正发挥作用?不会为用 @optics 注释的数据类生成伴随对象。 如果我没记错的话,这是一个注释处理器,因此应该使用 kapt 导入它,但是
尝试使用 OPTICS 来分段我的数据。 from sklearn.cluster import OPTICS X_scaler = StandardScaler().fit(X) X_final =
我正在尝试使用 sklearn.cluster.OPTICS 对已计算的相似性(距离)矩阵进行聚类,该相似性(距离)矩阵填充了归一化余弦距离(0.0 到 1.0) 但是无论我在 max_eps 和
我想要完成的事情: 我目前正在开发一个 xquery 脚本,以 html 表的形式检索 marklogic 数据库的数据,并可以对每一列进行排序和过滤。 数据作为具有外键的不同文档分布在多个目录中,就
我需要在 R 中构建一个优先级队列,我将在其中放置用于 OPTICS 聚类算法的有序种子对象(或对象的索引)。 一种可能性是用具有数组表示的堆来实现它,并在每次插入和减少键调用中传递堆数组,并返回更改
我是 ELKI 的新手,并且我已经成功调整了我想要运行的算法。我在 3K 坐标上使用它并且速度非常快 - 所以现在我尝试扩展到大约 1 MM 记录。现在我的运行速度为 30K,但已经几个小时了,它仍在
我似乎无法让这个算法在我的数据集上工作,所以我使用了数据的一个非常小的子集并尝试让它工作,但这也不起作用。 我想将预先计算的距离矩阵输入 ELKI,然后让它找到我的点的可达距离列表,但我得到的所有点的
CTLineGetBoundsWithOptions() 使用 CTLineBoundsOptions。其中一个选项是 kCTLineBoundsUseOpticalBounds 其文档说: Pass
我知道 DBSCAN 需要两个参数(minPts 和 Eps)。但是,我对 OPTICS 需要哪些参数感到困惑,因为一些消息来源说它需要 eps 而其他人说它只需要 minPts。 如果我尝试自动确定
我正在寻找一个不错的 OPTICS 的实现。 Python中的算法。我将使用它来形成基于密度的点簇((x,y) 对)。 我正在寻找可以接收 (x,y) 对并输出集群列表的东西,其中列表中的每个集群都包
我在 ELKI 中使用 OPTICS 实现时遇到问题环境。我在 DBSCAN 实现中使用了相同的数据,它就像一个魅力。可能我错过了一些带有参数的东西,但我无法弄清楚,一切似乎都是正确的。 数据是一个简
我想根据从cvCalcOpticalFlowPyrLK的输出中得到的所有点绘制一个边界框。 我已经完成了对物体的跟踪,并能够绘制出表示流动方向的线。但是,在将所有要点分组并归类为对象时遇到问题。 我正
我正在使用这样的圆形光学器件 import io.circe.parser._ import io.circe.optics._ import io.circe.optics.JsonPath._ v
我在 ELKI 上使用 OPTICSXi 和 rstartree 对地理数据集(纬度和经度)Gowalla 进行聚类,其中包含大约 600 万条记录,但 MiniGUI 总是显示“java 堆空间”和
似乎在父布局上设置 layoutMode="opticalBounds" 会禁用 9-Patch 内容区域。下面的屏幕截图是一个简单的 TextView: 而左侧的 FrameLayou
我的问题是如何让 MarkLogic 查询控制台 javascript API 将一列字符串格式化为日期。 直接处理字符串可以按预期工作: var d = new Date("3/12/2019");
我目前正在开展一个项目,我需要使用 Ocean Optics OmniDriver 与光谱仪进行通信。但是,我无法让它正常工作。当我在 Visual Studio 2017 中运行调试器时,我得到“框
The original paper和其他资源(维基百科)总是根据半径 ε(必须有超过 MinPts 个邻居)使用像 within 或 up to 这样的表达式来定义核心对象。这留下了解释这个半径是否
我有三星 S10,它具有视频稳定功能。使用系统默认的相机应用程序,我可以看到它启用和未启用时的区别:首先,如果它已启用,则会有一些缩放预览,其次,它在设备移动期间很明显。 我尝试使用 Camera2
我是一名优秀的程序员,十分优秀!