Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
如何从JSON格式解析和打印嵌套数组值_Json_Python 3.x - Fatal编程技术网

如何从JSON格式解析和打印嵌套数组值

如何从JSON格式解析和打印嵌套数组值,json,python-3.x,Json,Python 3.x,我想在JSON下解析并打印,但打印时出现问题 JSON格式为: {"categories": [ "Firewall Permit","Custom Policy 1" ] } 我曾经使用下面的代码来实现这一点,但我只能打印“防火墙许可证” 但我想打印如下内容:防火墙许可,自定义策略 请在这方面指导我。如何使用这个JSON字典 您可以使用Python 3print函数的功能: for entry in json_data: print(*entry['categories'],

我想在JSON下解析并打印,但打印时出现问题

JSON格式为:

{"categories": 
[
  "Firewall Permit","Custom Policy 1"
]
}
我曾经使用下面的代码来实现这一点,但我只能打印“防火墙许可证”

但我想打印如下内容:
防火墙许可,自定义策略


请在这方面指导我。如何使用这个JSON字典

您可以使用Python 3
print
函数的功能:

for entry in json_data:
    print(*entry['categories'], sep=', ')
印刷品:

Firewall Permit, Custom Policy 

您可以通过以下简单方式完成:

print(', '.join(json_data['categories']))
print(', '.join(json_data['categories']))