CCNP 350-401 这题是什么答案啊 ?
根据题库第592题,请问答案是 A 还是 B? 在其他网站看到是 A,论坛里的题库答案是 B。Based on the router's API output in JSON format below, which Python code will display the value of the "hostname"key?
{
"response":[{
"family": "Switches",
"macAddress": "00:41:49:45:76:00",
"hostname": "SwitchIDF14",
"upTime": "352 days, 6:17:26:10",
"lastUpdated": "2020-07-12 21:15:29"
]}
}
A. json_data= json.loads(response.text)
print(json_data['response']['family']
B. json_data= response.json()
print(json_data['response']['hostname']
我也找了下不知道是论坛题库错还是网上错 心魅d 发表于 2022-8-12 11:16
我也找了下不知道是论坛题库错还是网上错
不只是这一题 我刚刚对比了好几题 答案有些都和网上的不一样 答案是B喔, 要先從list裡取出第一個dict值。 是B啊 答案应该是C吧:
import json
response = """
{
"response":[{
"family": "Switches",
"macAddress": "00:41:49:45:76:00",
"hostname": "SwitchIDF14",
"upTime": "352 days, 6:17:26:10",
"lastUpdated": "2020-07-12 21:15:29"
}]
}
"""
json_data = json.loads(response)
print(json_data['response']['hostname'])
运行结果:
c:\Test\temp\json>python test_json.py
SwitchIDF14
c:\Test\temp\json> 答案是"B"。JSON 语法[ ] 代表阵列。虽然题中response只带一个元素,但仍要用指出元素位置。 cableman 发表于 2022-8-12 12:41
答案是"B"。JSON 语法[ ] 代表阵列。虽然题中response只带一个元素,但仍要用指出元素位置。
B 中的response.json() 语法是错的。
C中也有: print(json_data['response']['hostname'])
感谢楼主分享!!!!!!!!!! {:6_267:} popeye2008 发表于 2022-8-13 11:07
B 中的response.json() 语法是错的。
C中也有: print(json_data['response']['hostname'])
B是正確的喔,題目是根據router's API,使用的是requests套件(關鍵), response.json() 來承接JSON物件。
C錯在print(json_data['response'])其hostname沒有引號。
可以參考以下程式碼:
# import requests module
import requests
# Making a get request
response = requests.get('https://api.github.com')
# print response
print(response)
# print json content
print(response.json()) I hope someone has 答案是B Nice!
页:
[1]