我有一个config.json文件,其中包含一系列组织:
config.json
{
"organisations": [
{ "displayName" : "org1", "bucketName" : "org1_bucket" },
{ "displayName" : "org2", "bucketName" : "org2_bucket" },
{ "displayName" : "org3", "bucketName" : "org3_bucket" }
]
}
如何获取所有组织名称的数组
这就是我尝试过的:
from python_json_config import ConfigBuilder
def read_config():
builder = ConfigBuilder()
org_array = builder.parse_config('config.json')
# return all firstNames in org_array
此外,我们无法知道
ConfigBuilder
或builder.parse_config
会发生什么,因为我们无法访问该代码,所以很抱歉没有考虑您的示例输出:
使用列表理解,这很简单。以读取json文件
使用
lambda
和map
来获取仅组织名称的数组如果您想将
json
数据从文件读入dictionary
,可以通过以下方式实现相关问题 更多 >
编程相关推荐