背景:
我有以下 JSON 数据结构示例:
{'sensor' : [
{'assertions_enabled': 'ucr+',
'deassertions_enabled': 'ucr+',
'entity_id': '7.0',
'lower_critical': 'na',
'lower_non_critical': 'na',
'lower_non_recoverable': 'na',
'reading_type': 'analog',
'sensor_id': 'SR5680 TEMP (0x5d)',
'sensor_reading': {'confidence_interval': '0.500',
'units': 'degrees C',
'value': '42'},
'sensor_type': 'Temperature',
'status': 'ok',
'upper_critical': '59.000',
'upper_non_critical': 'na',
'upper_non_recoverable': 'na'}
]}
传感器列表实际上将包含许多包含传感器信息的字典。
Problem:
我正在尝试使用 jsonpath 查询列表以返回具有以下内容的传感器字典的子集sensor_type=='Temperature'
但我得到了'False'
返回(不匹配)。这是我的 jsonpath 表达式:
results = jsonpath.jsonpath(ipmi_node, "$.sensor[?(@.['sensor_type']=='Temperature')]")
当我删除过滤表达式并只使用"$.sensor.*"
我得到了所有传感器的列表,所以我确定问题出在过滤器表达式中。
我扫描了多个网站/帖子来获取示例,但似乎找不到任何特定于 Python 的内容(Javascript 和 PHP 似乎更突出)。有人可以提供一些指导吗?