Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 嵌套JSON不作为dict中的键加载_Python_Json - Fatal编程技术网

Python 嵌套JSON不作为dict中的键加载

Python 嵌套JSON不作为dict中的键加载,python,json,Python,Json,我现在在一个名为returned_data的dict中有下面的JSON-我想把帐户ID取出来,但是看起来它没有识别出任何比第二级更深的键。例如: returned_data["command1"]["customers"] 工作 不起作用 returned_data["command1"]["customers"].keys() 不显示任何键 我需要做什么才能引用acctid { "command1": { "customers": [{ "cit

我现在在一个名为returned_data的dict中有下面的JSON-我想把帐户ID取出来,但是看起来它没有识别出任何比第二级更深的键。例如:

returned_data["command1"]["customers"]
工作

不起作用

returned_data["command1"]["customers"].keys() 
不显示任何键

我需要做什么才能引用acctid

{
"command1": {

        "customers": [{
            "city": "none",
            "cust_id": 204567,
            "name_first": "John",
            "name_last": "Smith",
            "zip": "39199",
            "street_addr_1": "1 Bat St",

            "phones": [
                {"phone_number": "(01) 5555555",
                "phone_type": "Mobile",
                "phone_code": "C"
                },
                {"phone_number": "(01) 5555555",
                "phone_type": "Home",
                "phone_code": "E"
                }
                    ],

            "email_addr": "test@test.com",
            "acctid": 123456,
            "state": "WA",
            "add_user": "JR",
            "country": "AUS",
            "acct_type": "P",
                }
                ],
        "ref": "123456",
        "result": 0
            },

"header": {"src_sys_type": 2,
    "ver": 1,
    "result": 0}

 }

这就是你需要的

['command1']['customers'][0]['acctid']

您可能会遇到索引错误。之所以需要
[0]
,是因为
'customers'
后面的括号。正如评论所说,这是一个列表,而不是json。

返回的数据[“command1”][“customers”]
是一个列表,而不是一个字典。这足够了吗,或者您需要知道如何在Python中使用列表吗?看起来我需要运用我对列表的知识-谢谢!
['command1']['customers'][0]['acctid']