我正在使用https://github.com/json4s/json4s。如何将其值如JDouble
,JBool
转换为相应的Scala数据类型 - Double
和Boolean
?将JDouble转换为Double(JSON库)
UPDATE:
scala> (json \ "status")
res8: org.json4s.JValue = JBool(false)
scala> (json \ "status").extract[Boolean]
<console>:16: error: No org.json4s.Formats found. Try to bring an instance of org.json4s.Formats in scope or use the org.json4s.DefaultFormats.
(json \ "status").extract[Boolean]
不知道,但尝试像这样'(jv \“items”\“type”)。extractOpt [String]'如果它工作! – Shrey
@Shrey,jv,“物品”和“类型”是什么?我必须纠正它为我的JSON结构才能够尝试它。 –