为什么存在语法错误-在此Couchbase N1QL查询中为0?

问题描述 投票:1回答:1

我在Couchbase中有一个文档:

{
  "ResponseMessage": {
    "0": {
      "y2": "1",
      "y1": "2"  
    },
    "1": { 
      "x1": "499",
      "x2": "O"
    },
    "CacheTimeOut": "0",
    "ObjectID": "6632 87d7"
  }
}

当我执行此查询时,

select ResponseMessage.0.y1 from `my-bucket`

我收到此回复:

[
  {
    "code": 3000,
    "msg": "syntax error - at 0",
    "query": "select ResponseMessage.0.y1 from `my-bucket`"
  }
]

如果“ 0”是“ a0”,则它不会返回错误。

是否可以在N1QL查询中写引用“ 0”的JSON密钥名称?

json couchbase n1ql
1个回答
1
投票

0是文字数字(在JSON和N1QL中均是)。因此,您将需要对其进行转义。

解决方案是:

select ResponseMessage.`0`.y1 from `my-bucket`

使用此字符`(反引号即可转义)>>

© www.soinside.com 2019 - 2024. All rights reserved.