是否可以在不安装Play的情况下使用JSON库?

时间:2015-04-17 20:44:27

标签: json scala playframework-2.0

在我的build.sbt

lazy val commonSettings = Seq(
  version := "1.0.0",
  scalaVersion := "2.11.6"
)
lazy val root = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "myapp",
    libraryDependencies ++= Seq(
      "com.typesafe.play" % "play-json_2.11" % "2.3.4",
      "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test",
      "junit" % "junit" % "4.12" % "test"
    )
  )
resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")

它汇编得很好。现在在代码中我使用import play.api.libs.json._但是编译器给出了错误说"未找到:对象播放"。显然我没有安装游戏。是否可以在不安装Play的情况下使用play-json库?

1 个答案:

答案 0 :(得分:8)

考虑这个简单的sbt项目:

build.sbt

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play-json" % "2.3.4"
)

resolvers ++= Seq("Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/")

然后你可以运行:

sbt console
import play.api.libs.json._
Json.parse("{}")
> res0: play.api.libs.json.JsValue = {}

是的,你可以玩没有Play的play-json。如果它在您的项目中不起作用,请尝试重新启动SBT或在SBT中进行清理,重新加载,更新,编译。