【发布时间】:2017-07-23 00:29:16
【问题描述】:
这个json文件:
[ {
"irc_server" : null,
"ssh_keys" : [ ],
"branches" : {
"master" : {
"running_builds" : [ ],
"recent_builds" : [ {
"outcome" : "no_tests",
"status" : "no_tests",
"build_num" : 1,
"vcs_revision" : "748f8679cfc850582e3ada08210d8566a291328c",
"pushed_at" : "2017-07-21T03:39:46.230Z",
"added_at" : "2017-07-21T03:36:24.657Z"
} ],
"last_non_success" : {
"outcome" : "no_tests",
"status" : "no_tests",
"build_num" : 1,
"vcs_revision" : "748f8679cfc850582e3ada08210d8566a291328c",
"pushed_at" : "2017-07-21T03:39:46.230Z",
"added_at" : "2017-07-21T03:36:24.657Z"
}
}
}]
我如何解析它:
projectsurl = get(API_PATH['PROJECTS'].format(self._token)) #get json data from url
decodedjson = projectsurl.content.decode('utf-8') #decode to string
jsondata = json.loads(decodedjson) #json obj
return jsondata['vcs_revision']
如何从该数组中获取特定对象?每当我打电话给return jsondata['vcs_revision'] 它说我需要一个 int 而不是字符串
【问题讨论】:
标签: python arrays json dictionary