我想逐行打印json文件,然后将其存储到类函数中:

时间:2019-11-22 03:15:10

标签: dictionary python-3.7

data = {"books": [
        {
          "book": "Three Blind Mice",
          "author": "John Ivimey",
          "price": 2
        },
        {
          "book": "Wizard of Oz",
          "author": "Frank Baum",
          "price": 3
        },
      ]
    }

我错误“列表索引必须是整数或切片,而不是str”

for i in data:
    print("book: {}".format(data[i]["book"]))

如何像这样打印它:

1. book: Three Blind Mice
   author: John Ivimey
   price: 2

2. book: "Wizard of Oz"
   author: "Frank Baum"
   price: 3

我也想将其存储到一个类中以供以后参考。请帮助

0 个答案:

没有答案