我正在尝试这个站点的代码(稍作修改),我遇到了一个问题,将结果返回为Int
.
class NeoService(rootUrl: String) {
def this() = this("http://default/neo/URL/location/db/data")
val stdHeaders = Seq(
("Accept", "application/json"),
("Content-Type", "application/json")
)
def executeCypher(query: String, params: JsObject) : Future[Response] = {
WS.url(rootUrl + "/cypher").withHeaders(stdHeaders:_*).post(Json.obj(
"query" -> query,
"params" -> params
))
}
def findNode(id: Int) : Future[Option[Int]] = {
val cypher = """
START n=node({id})
RETURN id(n) as id
""".stripMargin
val params = Json.obj("id" -> id)
for (r <- executeCyhper(cypher, params)) yield {
val data = (r.json \ "data").as[JsArray]
if (data.value.size == 0)
None
else
Some(data.value(0).as[JsArray].value(0).as[Int])
}
}
}
如果我将有效的 id 传递给findNode()
它会给我这个错误:
[JsResultException: JsResultException(errors:List((,List(ValidationError(validate.error.expected.jsnumber,WrappedArray())))))]
在该行Some(data.value(0).as[JsArray].value(0).as[Int])
,如果我传递一个不存在的 id,它会给我这个错误:
[JsResultException: JsResultException(errors:List((,List(ValidationError(validate.error.expected.jsarray,WrappedArray())))))]
在线val data = (response.json \ "data").as[JsArray]
如果我只是通过Int
这样的:
... else
Some(10)...
它工作正常。我不知道发生了什么以及错误消息试图告诉我什么。