我正在尝试用Specs2测试Json,但是我总是得到一个解析错误。
也许因为我用的是JObect?
val j: JObject = "hello" -> "world"
j must */("hello")这是错误:
Search_fields
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谢谢
发布于 2013-09-28 18:02:13
specs2 json匹配器是Matcher[String]。我怀疑您看到的是试图解析specs2匹配器无法解析的Lift Json对象的.toString表示。相反,您应该匹配Lift Json对象的正确字符串表示。
发布于 2013-09-27 20:58:42
如果您指的是编译错误,请检查所有导入,然后重试:
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))))https://stackoverflow.com/questions/19049355
复制相似问题