Robot Framework如何使用第二个值获取JSON值

mw3dktmi  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(259)

如果我知道一个特定的值,我如何从JSON中获得某个值。如果我想提取汽车类型并且我知道汽车名称。我尝试了不同的变化:${GetType}= Get Value From Json ${CarList.json()} $..type[?($.name=Focus)]

[
  {
    "Manuafacture": "BMW",
    "Engine": [
      {
        "volume": 3,
        "filter": 222,
        "name": "Turbo-dd"
      }
    ],
    "name": "320",
    "type": "333-44-12"
  },
  {
    "Manuafacture": "Ford",
    "Engine": [
      {
        "volume": 2,
        "filters": 1111,
        "name": "doch"
      }
    ],
    "name": "Focus",
    "type": "444-55-33"
  },
  {
    "Manuafacture": "Audi",
    "Engine": [
      {
        "volume": 3,
        "filters": 444,
        "name": "TFSI"
      }
    ],
    "name": "A6",
    "type": "999-88-77"
  }
]
f0brbegy

f0brbegy1#

在过滤器表达式中,您引用的不是当前元素(@),而是根元素($)。等号也应该使用两次(==)。这样的东西应该是可行的:
$[?(@.name=="Focus")].type

相关问题