簡體   English   中英

如何使用 JsonPath (JayWay) 連接 json 元素

[英]How to concatenate json elements with JsonPath (JayWay)

有一個簡單的json:

{ "Keys": [
  {"Format": "A", "Subtype": "A1"},
  {"Format": "A",  "Subtype": "A2"},
  {"Format": "B",  "Subtype": "A1"}]
}

我想使用 JsonPath 表達式(沒有 Java 特定實現)生成這個結果(格式 + 子類型連接):

 AA1
 AA2
 BA1

是否可以使用 jsonPath 連接字符串元素?

謝謝

因此,以下將給出AA1

$.concat($.Keys[0].Format,$.Keys[0].Subtype)

同樣

$.concat($.Keys[1].Format,$.Keys[1].Subtype) -- AA2
$.concat($.Keys[2].Format,$.Keys[2].Subtype) -- BA1

我知道這篇文章是前一段時間,但我正在尋找類似的問題。 這不是解決方案嗎?

  $.Keys[0].Format$.Keys[0].Subtype
  $.Keys[1].Format$.Keys[1].Subtype
  $.Keys[2].Format$.Keys[2].Subtype

您可以構建 JSON 路徑表達式,例如:

$.Keys[0].Format -- A
$.Keys[1].Format -- A
$.Keys[2].Format -- B

並在下面的鏈接中引用此 SO 線程以最終使用 Jayway 解析它。

暫無
暫無

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

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