【发布时间】:2023-12-09 14:27:01
【问题描述】:
我从 Web 服务获得的 JSON 表示法:
{
"students": [
{
"studentId": 127292,
"studentName": "Mary"
},
{
"studentId": 15555,
"studentName": "Joe"
}
]
}
我正在尝试迭代 JSON 对象并根据学生姓名获取学生 ID。
例如,如果我必须得到 'Joe' 中的 studentId,我们如何在 Python 中处理它?
try:
req = urllib2.Request(url, headers = header)
response = urllib2.urlopen(req)
jsonObject = json.load(response)
except Exception as e:
print e
【问题讨论】:
-
Python 没有“JSON 对象”之类的东西。有 JSON 表示法,还有 Python 对象。看看 Python
dict和list类型。
标签: python json python-2.7 urllib2