使用Lift JSON解析JSON问题

时间:2014-10-10 15:56:01

标签: scala lift-json

我正在尝试使用Lift JSON库解析JSON。我已经使用SBT导入了库,方法是将以下语句添加到build.sbt文件中:

libraryDependencies +="net.liftweb" % "lift-json" % "2.0"

我启动SBT并使用“console”命令运行Scala解释器。

然后我运行以下两个语句:

import net.liftweb.json._
parse(""" { "numbers" : [1, 2, 3, 4] } """)

在第二个语句之后,我收到以下错误:

<console>:11: error: not found: value parse
       parse(""" { "numbers" : [1, 2, 3, 4] } """)

为了确保它不是我的项目的问题,我已经启动了一个干净的项目,只导入了Lift JSON库。结果相同。我甚至尝试了另一种JSON库(json4s),但是当它到达parse语句时它给出了完全相同的问题: - (

我正在运行以下版本: 斯卡拉2.11.2 SBT 0.13.6 提升JSON 2.0

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

Lift 2.0很老了。只需使用2.5代替。 Afaict 2.0实际上在parse包对象中没有json方法。

答案 1 :(得分:1)

来自scala版本2.11.6的'scala repl'和一个更高版本的lift-json(http://mvnrepository.com/artifact/net.liftweb/lift-json_2.11

从lift-json README.md文件运行示例 https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/

您还可以使用lift:json README.md

中建议的“:require”(如下所示)将paranamer.jar文件添加到classpath
$ scala

Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :require lift-json_2.11-3.0-M5-1.jar

Added '<absolute path to>/lift-json/lift-json_2.11-3.0-M5-1.jar' to classpath.

scala> import net.liftweb.json._

import net.liftweb.json._

scala> parse(""" { "numbers" : [1, 2, 3, 4] } """)

res0: net.liftweb.json.JValue = JObject(List(JField(numbers,JArray(List(JInt(1), JInt(2), JInt(3), JInt(4))))))