簡體   English   中英

MarkLogic示例查詢-JSON鍵中的下划線不起作用嗎?

[英]MarkLogic Query By Example - underscore in JSON key not working?

我在MarkLogic中具有JSON格式的以下條目:

{
   "identifier":"user1",
   "attributesList": [
      {
        "firstName": "James",
        "address_1": "Farcity"
      }
   ]
 }

如果可以,我將使用以下格式進行查詢:

{
 $query:
 {
   "identifier":"user1",
   "attributesList": [
      {
        "firstName": "James"
      }
   ]
 }
}

這將匹配並返回計數為1的預期結果,因為“ firstName”等於“ James”。

但是,如果我執行以下操作:

{
 $query:
 {
   "identifier":"user1",
   "attributesList": [
      {
        "address_1": "Farcity"
      }
   ]
 }
}

即使“ address_1”與“ Farcity”完全匹配也不會返回任何結果。 我已經在其他JSON密鑰上進行了嘗試,除了在密鑰中帶有下划線的字符之外,其他所有鍵都可以正常使用。這是保留字符嗎? 如果是這樣,是否有一種方法可以對此進行轉義,以便仍然可以匹配鍵“ address_1”或“ county_state”?

看起來Json對象將下划線轉換為雙下划線

運行這個:

xquery version "1.0-ml";

import module namespace json="http://marklogic.com/xdmp/json"
 at "/MarkLogic/json/json.xqy";

let $j :=
 '{
   "identifier":"user1",
   "attributesList": [
      {
        "firstName": "James",
        "address_1": "Farcity"
      }
   ]
}'
return 
 json:transform-from-json( $j)

你會把這個放出來的

<json type="object" xmlns="http://marklogic.com/xdmp/json/basic">
  <identifier type="string">user1</identifier>
  <attributesList type="array">
    <json type="object">
      <firstName type="string">James</firstName>
      <address__1 type="string">Farcity</address__1>
    </json>
  </attributesList>
</json>

因此,請嘗試使用雙下划線進行查詢。 另外,如果您使用的是Marklogic 6或7,它將Json轉換為xml。 因此您可以嘗試使用XML格式通過示例查詢。

有關將JSON字段名稱映射到QName的確切算法和函數,請參見http://docs.marklogic.com/xdmp:encode-for-NCName

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM