解析嵌套的JSON响应Python

这个问题在这里已经有了答案:

  • 使用'for'循环遍历字典12个答案

  • 您可以使用字典对象中的keys方法来获取密钥,然后迭代以获取所需的值。

    例:

    d = {
        "available_projects": {
            "model001": {
                "available_models": [
                    "model_20171004-090552"
                ],
                "status": "ready"
            },
            "model002": {
                "available_models": [
                    "model_20171013-143108"
                ],
                "status": "ready"
            },
            "model002b": {
                "available_models": [
                    "model_20171013-151458"
                ],
                "status": "ready"
            }
        }
    }
    
    for i in d["available_projects"].keys():
        print i, "=" , d["available_projects"][i]['available_models'][0]
    

    输出:

    model001 = model_20171004-090552
    model002b = model_20171013-151458
    model002 = model_20171013-143108
    
    链接地址: http://www.djcxy.com/p/30377.html

    上一篇: Parsing nested JSON response Python

    下一篇: How to unpack key,value pairs in python?