{
"export": {
"version": "3.4",
"date": "2018-08-09T13:19:46Z",
"groups": [
{
"name": "Templates"
}
],
"templates": [
{
"template": "Template OS",
"name": "Template OS",
"description": "",
"groups": [
{
"name": "Datawhatiwant"
}
],
这是JSON代码的相关部分,我想要值为 datawhatiwant 。
但是,如果我使用print json_data["export"]
,则会出现此错误:
TypeError: string indices must be integers
那么如何获得 datawhatiwant ?
答案 0 :(得分:2)
您需要先解码json
import json
print(json.loads(json_data)["export"])
我认为应该会更好。