从json文件

时间:2017-10-18 01:20:59

标签: json python-3.x

我有一个像这样的json文件,有多个变量

{
  "resource_folder_name": "my resources",
  "itunes_id":"some_item",
  "default_language":["en", "es", "in"],
  "default_country":["mt", "in", "uk", "usa"]
}

如何迭代它以创建类似于

的字典结构
{
  ["resource_folder_name"]= "my resources",
  ["itunes_id"]="some_item",
  ["default_language"]=["en", "es", "in"],
  ["default_country"]["mt", "in", "uk", "usa"]
}

然后我想传递这个字典来创建一个plist,我需要遍历列表来添加项目。

我试过的是

def return_params():
    filename = 'params.json'
    with open(filename) as json_file:
        data = json.load(json_file)

    local_vars = {}

    for var in data:
        print('Var = '+var + ' & Data = '+data[var])

        if('' not in data[var]):
            local_vars[var] = data[var]
        else:
            local_vars[var] = data[var]

    return local_vars

但这只能阅读

  

key =字符串值

类型的数据,而不是列表或词典。

0 个答案:

没有答案