Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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 3.x 如何解析多重列表_Python 3.x_List - Fatal编程技术网

Python 3.x 如何解析多重列表

Python 3.x 如何解析多重列表,python-3.x,list,Python 3.x,List,当进行类似allorders=getallorders()的调用时 它返回的列表如下所示 { "orders": [ { "order_id": “123", "status": "REJECTED", "validity": "DAY", }, { "order_id": “343”, "status": "REJECTED", "validity": "DAY", }

当进行类似allorders=getallorders()的调用时

它返回的列表如下所示

{
  "orders": [
    {
      "order_id": “123", 
      "status": "REJECTED",
      "validity": "DAY", 
    }, 
    {
      "order_id": “343”, 
      "status": "REJECTED",
      "validity": "DAY",   
    }
  ]
}

如何遍历此列表并获取每个订单id和相应的状态?

使用此for循环,您可以遍历json应答allorder并获得所需的键及其值

for order in allorders['orders']:
    print('id: ', order['order_id'])
    print('status: ', order['status'])

请不要只发布代码作为答案,而是解释代码的作用以及如何解决问题。带有解释的答案通常质量更高,更容易吸引选票。