通过内容python在dict循环中分配var

时间:2014-02-07 21:02:37

标签: python getjson

我在我的脚本中传递了一些JSON,并希望能够将每个键名设置为其值,以便我可以单独调用它们作为变量

示例{'provider':'我','visitInformation':无,'parkingInformation':无, 'identifier':'123'}

所以我可以调用每个并且它解析为值

- >>>提供商

- >>>我

到目前为止,这是我的代码;

def org(cqc):
r = requests.get(url + cqc)
r = (r.json())

a={}

for (key, value) in (r.items()) :
    a[{0}.format(key)] = [{1}.format(value)]

目前正在返回:

Traceback (most recent call last):
          File "C:/Python33/test-files/org-api.py", line 43, in <module>
          org(get_org)
          File "C:/Python33/test-files/org-api.py", line 17, in org
          globals()[{0}.format(key)] = [{1}.format(value)]
AttributeError: 'set' object has no attribute 'format'

0 个答案:

没有答案