使用 Confluence 的响应 Rest API
Using Response of Confluence Rest API
我正在执行在我们的 Confluence Cloud 实例中创建 Space 和页面的批量操作。我不是特别的程序员。在使用 运行 API 使用 Python 之后,我们需要一些帮助来使用我们得到的响应。输出为 Json 格式。如果这是输出,请告诉我如何访问标题和 ID -
{
"content": {
"id": "398852913",
"type": "page",
"status": "current",
"title": "Test Project Name 1 SOW",
"childTypes": {},
"macroRenderedOutput": {},
"restrictions": {},
"_expandable": {
"container": "",
"metadata": "",
"extensions": "",
"operations": "",
"children": "",
"history": "/rest/api/content/398852913/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "",
"space": "/rest/api/space/TestSpace1",
},
"_links": {
"webui": "/spaces/TestSpace1/pages/398852913/Test+Project+Name+1++SOW",
"self": "https://enerzinx.atlassian.net/wiki/rest/api/content/398852913",
"tinyui": "/x/MQPGFw",
},
},
"title": "Test Project Name 1 SOW",
"excerpt": "file-list",
"url": "/spaces/TestSpace1/pages/398852913/Test+Project+Name+1++SOW",
"resultGlobalContainer": {
"title": "TestSpace1",
"displayUrl": "/spaces/TestSpace1",
},
"breadcrumbs": [],
"entityType": "content",
"iconCssClass": "aui-iconfont-page-default",
"lastModified": "2020-06-24T06:17:32.333Z",
"friendlyLastModified": "Jun 24, 2020",
"score": 0.59390986,
}
如果您的响应是 JSON 格式的字符串,您首先需要将 JSON 解析为字典。为此,您可以使用 json
模块,它是标准模块集的一部分。解析 JSON 之后,您可以使用字典查找访问键。
>>> import json
>>>
>>> json_string = '{"foo": "bar"}'
>>> json_dict = json.loads(json_string)
>>> json_dict["foo"]
'bar'
您的回复 JSON 似乎会生成一个嵌套字典,因此标题的路径类似于 json_dict["foo"]["bar"]
.
我正在执行在我们的 Confluence Cloud 实例中创建 Space 和页面的批量操作。我不是特别的程序员。在使用 运行 API 使用 Python 之后,我们需要一些帮助来使用我们得到的响应。输出为 Json 格式。如果这是输出,请告诉我如何访问标题和 ID -
{
"content": {
"id": "398852913",
"type": "page",
"status": "current",
"title": "Test Project Name 1 SOW",
"childTypes": {},
"macroRenderedOutput": {},
"restrictions": {},
"_expandable": {
"container": "",
"metadata": "",
"extensions": "",
"operations": "",
"children": "",
"history": "/rest/api/content/398852913/history",
"ancestors": "",
"body": "",
"version": "",
"descendants": "",
"space": "/rest/api/space/TestSpace1",
},
"_links": {
"webui": "/spaces/TestSpace1/pages/398852913/Test+Project+Name+1++SOW",
"self": "https://enerzinx.atlassian.net/wiki/rest/api/content/398852913",
"tinyui": "/x/MQPGFw",
},
},
"title": "Test Project Name 1 SOW",
"excerpt": "file-list",
"url": "/spaces/TestSpace1/pages/398852913/Test+Project+Name+1++SOW",
"resultGlobalContainer": {
"title": "TestSpace1",
"displayUrl": "/spaces/TestSpace1",
},
"breadcrumbs": [],
"entityType": "content",
"iconCssClass": "aui-iconfont-page-default",
"lastModified": "2020-06-24T06:17:32.333Z",
"friendlyLastModified": "Jun 24, 2020",
"score": 0.59390986,
}
如果您的响应是 JSON 格式的字符串,您首先需要将 JSON 解析为字典。为此,您可以使用 json
模块,它是标准模块集的一部分。解析 JSON 之后,您可以使用字典查找访问键。
>>> import json
>>>
>>> json_string = '{"foo": "bar"}'
>>> json_dict = json.loads(json_string)
>>> json_dict["foo"]
'bar'
您的回复 JSON 似乎会生成一个嵌套字典,因此标题的路径类似于 json_dict["foo"]["bar"]
.