我有以下 json 文件:
标签.tg
[{"_type": "tag", "name": "A0", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ float32_t A0; \\/**< The derived gain, A0 = Kp + Ki + Kd . *\\/$/", "typeref": "float32_t", "kind": "member", "scope": "__anond9a59aba0f08", "scopeKind": "struct"},
{"_type": "tag", "name": "A0", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q15_t A0; \\/**< The derived gain, A0 = Kp + Ki + Kd . *\\/$/", "typeref": "q15_t", "kind": "member", "scope": "__anond9a59aba0d08", "scopeKind": "struct"},
{"_type": "tag", "name": "A0", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q31_t A0; \\/**< The derived gain, A0 = Kp + Ki + Kd . *\\/$/", "typeref": "q31_t", "kind": "member", "scope": "__anond9a59aba0e08", "scopeKind": "struct"},
{"_type": "tag", "name": "A1", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ float32_t A1; \\/**< The derived gain, A1 = -Kp - 2Kd. *\\/$/", "typeref": "float32_t", "kind": "member", "scope": "__anond9a59aba0f08", "scopeKind": "struct"},
{"_type": "tag", "name": "A1", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q15_t A1;$/", "typeref": "q15_t", "kind": "member", "scope": "__anond9a59aba0d08", "scopeKind": "struct"},
{"_type": "tag", "name": "A1", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q31_t A1; \\/**< The derived gain, A1 = -Kp - 2Kd. *\\/$/", "typeref": "q31_t", "kind": "member", "scope": "__anond9a59aba0e08", "scopeKind": "struct"},
{"_type": "tag", "name": "A1", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q31_t A1; \\/**< The derived gain A1 = -Kp - 2Kd | Kd.*\\/$/", "typeref": "q31_t", "kind": "member", "scope": "__anond9a59aba0d08", "scopeKind": "struct"},
{"_type": "tag", "name": "A2", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ float32_t A2; \\/**< The derived gain, A2 = Kd . *\\/$/", "typeref": "float32_t", "kind": "member", "scope": "__anond9a59aba0f08", "scopeKind": "struct"},
{"_type": "tag", "name": "A2", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q15_t A2;$/", "typeref": "q15_t", "kind": "member", "scope": "__anond9a59aba0d08", "scopeKind": "struct"},
{"_type": "tag", "name": "A2", "path": "Drivers\\CMSIS\\Include\\arm_math.h", "pattern": "/^ q31_t A2; \\/**< The derived gain, A2 = Kd . *\\/$/", "typeref": "q31_t", "kind": "member", "scope": "__anond9a59aba0e08", "scopeKind": "struct"},
{"_type": "tag", "name": "ABFSR", "path": "Drivers\\CMSIS\\Include\\core_cm7.h", "pattern": "/^ __IOM uint32_t ABFSR; \\/*!< Offset: 0x2A8 (R\\/W) Auxiliary Bus Fault Status /", "typeref": "__IOM uint32_t", "kind": "member", "scope": "__anoncee350000a08", "scopeKind": "struct"},
{"_type": "tag", "name": "ABR", "path": "Drivers\\CMSIS\\Device\\ST\\STM32F7xx\\Include\\stm32f767xx.h", "pattern": "/^ __IO uint32_t ABR; \\/*!< QUADSPI Alternate Bytes register, Address offs/", "typeref": "__IO uint32_t", "kind": "member", "scope": "__anonea3271f52708", "scopeKind": "struct"},
{"_type": "tag", "name": "ACPR", "path": "Drivers\\CMSIS\\Include\\core_cm3.h", "pattern": "/^ __IOM uint32_t ACPR; \\/*!< Offset: 0x010 (R\\/W) Asynchronous Clock Prescale/", "typeref": "__IOM uint32_t", "kind": "member", "scope": "__anoncee33efc1008", "scopeKind": "struct"},
{"_type": "tag", "name": "ACPR", "path": "Drivers\\CMSIS\\Include\\core_cm4.h", "pattern": "/^ __IOM uint32_t ACPR; \\/*!< Offset: 0x010 (R\\/W) Asynchronous Clock Prescale/", "typeref": "__IOM uint32_t", "kind": "member", "scope": "__anoncee3433d1008", "scopeKind": "struct"},
{"_type": "tag", "name": "ACPR", "path": "Drivers\\CMSIS\\Include\\core_cm7.h", "pattern": "/^ __IOM uint32_t ACPR; \\/*!< Offset: 0x010 (R\\/W) Asynchronous Clock Prescale/", "typeref": "__IOM uint32_t", "kind": "member", "scope": "__anoncee350001008", "scopeKind": "struct"},
{"_type": "tag", "name": "ACPR", "path": "Drivers\\CMSIS\\Include\\core_sc300.h", "pattern": "/^ __IOM uint32_t ACPR; \\/*!< Offset: 0x010 (R\\/W) Asynchronous Clock Prescale/", "typeref": "__IOM uint32_t", "kind": "member", "scope": "__anonccff54a21008", "scopeKind": "struct"},
{"_type": "tag", "name": "ACR", "path": "Drivers\\CMSIS\\Device\\ST\\STM32F7xx\\Include\\stm32f767xx.h", "pattern": "/^ __IO uint32_t ACR; \\/*!< FLASH access control register, Address offset: 0x00 *\\/$/", "typeref": "__IO uint32_t", "kind": "member", "scope": "__anonea3271f51408", "scopeKind": "struct"}
]
我已经检查了https://jsonlint.com/上 json 文件的有效性,看起来还不错。现在,我正在尝试将 json 文件加载到 Python 中的 TinyDB 数据库中:
from tinydb import TinyDB, Query
db = TinyDB("tag.tg")
Line = Query()
result = db.search(Line.name == "ADC_CCR_DELAY_2")
print(result)
代码在第二行失败db = TinyDB("tag.tg")
。我收到以下错误:
TypeError:列表索引必须是整数或切片,而不是 str
我做错什么了?我完全遵循 tinydb 文档https://pypi.python.org/pypi/tinydb:
>>> from tinydb import TinyDB, Query
>>> db = TinyDB('/path/to/db.json')
注意:
我使用的是 Python 3.6.1