这个json文件:
Dictionary<string,string> tableData = new Dictionary<string, string>();
var trNodes = eachNode.FindElements(By.TagName("tr"));
foreach (var trNode in trNodes)
{
var name = trNode.FindElement(By.CssSelector(".name")).Text.Trim();
var value = trNode.FindElement(By.CssSelector(".value")).Text.Trim();
tableData.Add(name,value);
}
var location = tableData["location"];
我如何解析它:
[ {
"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']
它说我需要一个int而不是一个字符串
答案 0 :(得分:1)
您需要执行jsondata[0]['vcs_revision']
,因为您的jsondata
是一个词典列表。