【发布时间】:2013-08-01 11:35:02
【问题描述】:
我正在尝试来自this 站点的代码(稍作修改),但在将结果作为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)...
它工作正常。我不知道发生了什么以及错误消息试图告诉我什么。
【问题讨论】:
标签: json scala neo4j playframework-2.1