【问题标题】:Neo4J transactional REST api string escape doesn't workNeo4J 事务性 REST api 字符串转义不起作用
【发布时间】:2015-09-21 13:53:33
【问题描述】:

在将 Cypher 查询发送到 Neo4J's transactional Cypher API 时,我遇到了以下错误:

Neo.ClientError.Request.InvalidFormat 无法反序列化请求: 无法识别的字符转义 '''(代码 39)

我的 Cypher 查询如下所示

MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\'s house';

虽然此查询在 Neo4J 的浏览器界面中执行时运行良好,但在使用 REST API 时会失败。这是一个错误还是我做错了什么?如果这不是一个错误,我该如何转义 ' 才能让它在两者中工作?

编辑: 我找到了this answer 并测试了三重单引号和三重双引号,但它们只是导致另一个Neo.ClientError.Request.InvalidFormat 错误被抛出。

注意:我使用的是 Neo4J 2.2.2

注意 2:以防万一,下面是我发送到端点的 JSON 正文。

{"statements":[
  {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\'s house';"}
]}

【问题讨论】:

    标签: java neo4j cypher


    【解决方案1】:

    你也必须避开 \:

    {"statements":[
      {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\\'s house';"}
    ]}
    

    但是如果你使用参数(推荐),你可以这样做

    {"statements":[
      {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = {lbl}",
       "parameters" : {"lbl" : "Jane Doe's house"}
      }
    
    ]}
    

    【讨论】:

    • 谢谢!应该知道这是因为 JSON。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2017-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多