0

我正在尝试使用 Specs2 测试 Json,但我总是遇到解析错误。

也许是因为我使用了 JObect?

val j: JObject = "hello" -> "world"
j must */("hello")

这是错误:

搜索字段

Could not parse:
JObject(List(JField(hello,JString(world))))
java.lang.Exception: Could not parse:
JObject(List(JField(hello,JString(world))))
    at net.liftweb.echidnasearch.QuerySearchSpec$$anonfun$1$$anonfun$apply$124.apply(QuerySearchSpec.scala:496)
    at net.liftweb.echidnasearch.QuerySearchSpec$$anonfun$1$$anonfun$apply$124.apply(QuerySearchSpec.scala:485)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

MatchQuery

谢谢

4

2 回答 2

1

specs2 json 匹配器是Matcher[String]. 我怀疑您所看到的是试图解析.toStringSpecs2 匹配器无法解析的 Lift Json 对象的表示。相反,您应该匹配 Lift Json 对象的正确字符串表示形式。

于 2013-09-28T10:02:13.477 回答
0

如果您的意思是编译错误,请检查所有导入并重试:

import net.liftweb.json.JsonDSL._
import net.liftweb.json._
val t:JObject = ("a" -> "b")

我在控制台中试过这个,它有效:

scala> val t:JObject = ("a" -> "b")
t: net.liftweb.json.JObject = JObject(List(JField(a,JString(b))))
于 2013-09-27T12:58:41.657 回答