我正在尝试使用 API 并检索 JSON。我正在尝试迭代记录并尝试获取结果。问题是下面是作为错误填充的警告。我不想将它们作为警告,但要找出匹配的解决方案可能不是排他性的错误消息。
case class Results(network: String,entity: String)
val jsonStr=parse(content)
val results = for {
JArray(results) <- jsonStr
JObject(result) <- results
JField("network",JString(network)) <- result
JField("entityId",JString(entityId)) <- result
} yield Results(network,entityId)
输出:
[error] /home/jenkins/builds/workspace/ProjectName/core/src/main/scala/Settlement_Feed.scala:42: match may not be exhaustive.
[error] It would fail on the following inputs: JArray(_), JBool(_), JDouble(_), JField(_, _), JInt(_), JNothing, JNull, JString(_)
[error] JObject(result) <- results
[error] ^
[error] /home/jenkins/builds/workspace/ProjectName/core/src/main/scala/Settlement_Feed.scala:41: match may not be exhaustive.
[error] It would fail on the following inputs: JBool(_), JDouble(_), JField(_, _), JInt(_), JNothing, JNull, JObject(_), JString(_)
[error] JArray(results) <- jsonStr
[error]
[error] two errors found
我已经尝试为此阅读 liftjson 和 scala 文档,但找不到很多有价值的信息来解决错误。我曾尝试保持 if 循环并尝试检查 jsonstr 的实例,但它没有用。任何建议都非常感谢。非常感谢。