Вопрос

Why does this code cause an error

import org.json4s.native.JsonMethods._
import org.json4s._

object Application extends App {
  implicit val formats = DefaultFormats
  val js = JString("120.0")
  val d = js.extract[Double]
  println(d)
}

it says Exception in thread "main" org.json4s.package$MappingException: Do not know how to convert JString(120.0) into double

Это было полезно?

Решение

Probably because Double is not a case class and doesn't have a constructor taking a String for argument.

How about js.extract[String].toDouble

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top