【发布时间】:2020-05-11 15:46:22
【问题描述】:
我正在使用this Python project 尝试与我的乐高 SBrick 互动。
如果我使用以下代码(一旦连接到 SBrick):
json_response = client.rr_get_adc(sbrick_id='11:22:33:44:55:66', timeout=5)
然后我可以打印 json_response 给我:
{"ret_code": 100, "temperature": 42.53253535, "voltage": 8.3954548125663}
我想访问“ret_code”来检查它是否等于 100,但如果我尝试:
print (json_response["ret_code"])
我收到此错误:
TypeError: string indices must be integers
如何将 ret_code 提取为整数?
【问题讨论】:
-
您是否尝试过解析 JSON?
标签: python json string dictionary