如果标识符是unquoted-string
(即A-Za-z0-9_
)以及字符串以A-Za-z_
开头,则可以直接地址.
From the grammar rule listed above identifiers can be one or more characters, and must start with A-Za-z_.
An identifier can also be quoted. This is necessary when an identifier has characters not specified in the unquoted-string
grammar rule. In this situation, an identifier is specified with a double quote, followed by any number of unescaped-char
or escaped-char
characters, followed by a double quote.
Source: JMESPath documentation, 100
由于您的标识符是0-9
,因此您必须对此标识符使用双引号字符串,因此为"1"
.
因此,您的工作Python代码是:
import jmespath
d = {'1': 'a'}
value = jmespath.search('"1"', d)
print(value)