列出Python字典实例的名称

时间:2016-09-15 23:40:29

标签: python json

我收集了Udemy的公开课程数据,并将其全部放在json文件中。每门课程都有一个标识号,在该标识号下存储所有数据。我可以完美地列出我想要的任何细节,除了这些标识号。

我如何自己列出这些数字?感谢。

{
    "153318":
    {
        "lectures data": "31 lectures, 5 hours video",
        "instructor work": "Academy Of Technical Courses, Grow Your Skills Today",
        "title": "Oracle Applications R12 Order Management and Pricing",
        "promotional price": "$19",
        "price": "$20",
        "link": "https://www.udemy.com/oracle-applications-r12-order-management-and-pricing/",
        "instructor": "Parallel Branch Inc"
    },
    "616990":
    {
        "lectures data": "24 lectures, 1.5 hours video",
        "instructor work": "Learning Sans Location",
        "title": "Cloud Computing Development Essentials",
        "promotional price": "$19",
        "price": "$20",
        "link": "https://www.udemy.com/cloud-computing-development-essentials/",
        "instructor": "Destin Learning"
    }
}

2 个答案:

答案 0 :(得分:3)

你想要那个词典的keys

import json
with open('course.json') as json_file:
    course=json.load(json_file)

print course.keys()
给予: [u'616990', u'153318']

答案 1 :(得分:0)

将json解析为python dict,然后遍历键

parsed = json.loads(input)

for key in parsed.keys():
    print(key)