从 json 文件解析 uri 密钥失败
parsing the uri key from json file is failing
大家好我正在尝试从 json 文件中解析 uri
密钥 - 它正在正确加载 JSON 文件,但是当我尝试解析 uri
它失败了:
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not TextIOWrapper
with open(RROOT) as data_file:
data = json.loads(data_file)
for key, value in data.items():
if key["uri"] in data:
print(value)
我在这里做错了什么?谢谢
首先,使用 json.load(获取文件对象)而不是 json.loads(获取 json 字符串)。
其次,key["uri"]会报错。如果您只想获取键“uri”的值,请执行以下操作:
with open(RROOT) as data_file:
data = json.load(data_file)
for value in data['uri']:
print(value)
大家好我正在尝试从 json 文件中解析 uri
密钥 - 它正在正确加载 JSON 文件,但是当我尝试解析 uri
它失败了:
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not TextIOWrapper
with open(RROOT) as data_file:
data = json.loads(data_file)
for key, value in data.items():
if key["uri"] in data:
print(value)
我在这里做错了什么?谢谢
首先,使用 json.load(获取文件对象)而不是 json.loads(获取 json 字符串)。
其次,key["uri"]会报错。如果您只想获取键“uri”的值,请执行以下操作:
with open(RROOT) as data_file:
data = json.load(data_file)
for value in data['uri']:
print(value)