【发布时间】:2017-10-24 09:56:05
【问题描述】:
{'PCCandidateDetails': {'BatchId': '456279',
'Candidate': 'Noori sahi ',
'CandidateId': '9124657',
'CenterName': 'K',
'ProjectName': 'PKKVY',
'QPName': 'Domestic Data Entry Operator(SSC/Q2212)',
'TrainingProviderName': 'OrionEdutechPrivateLimited'},
'PCTestScores': [{'MaxScore': 12,
'PCId': 'SRC/N3022_PC1',
'PCName': 'obtain sufficient information from the customer /client to understand the need and perform initial task',
'Percentage': 0,
'YourScore': 0},
{'MaxScore': 15,
'PCId': 'SRC/N3022_PC10',
'PCName': 'compares transcribed data, as displayed on a visual screen, document and corrects any errors with the source',
'Percentage': 0,
'YourScore': 0},
{'MaxScore': 5,
'PCId': 'SSC/N3022_PC11',
'PCName': 'obtain help or advice from specialist if the problem is outside his/her area of competence or experience',
'Percentage': 0,
'YourScore': 0}]}
我想遍历我使用网络请求获得的这个 json 对象。
import requests,ast
r = requests.get("some url")
data = r.text
data_dic = ast.literal_eval(data)
当我尝试循环 Json 时,我无法获取键值对中的预期输出。我想要这样的输出
BatchId : 456279
Candidate : Noori sahi
CandidateId :9124657 ...
等等。下面的代码是我的方法,但列表中的字典导致循环出现问题。
for i in data_dic:
for k,v in i.iteritems():
print k,v
我得到的错误是“str”对象没有属性“iteritems”。循环此类数据的正确方法是什么。
【问题讨论】:
标签: json django python-2.7 dictionary