Python/Rest。检查条目是否已存在并执行某些操作
我是python新手,希望执行以下操作: 我通过requests.get接收json。我想迭代它并打印所有没有“name”的条目:“xyz” 我有: 现在我想迭代j并说:只打印那些不是'name'的项目名称:'xyz'。比如:Python/Rest。检查条目是否已存在并执行某些操作,python,rest,for-loop,python-requests,Python,Rest,For Loop,Python Requests,我是python新手,希望执行以下操作: 我通过requests.get接收json。我想迭代它并打印所有没有“name”的条目:“xyz” 我有: 现在我想迭代j并说:只打印那些不是'name'的项目名称:'xyz'。比如: for entry in j: ... print entry ['name'] 谢谢。 问候 编辑: 我想具体说明我的问题: 我只想在j中不存在项时添加它。因此,我需要检查“name”字段,如下所示: [ { "uri" : "/item/
for entry in j:
...
print entry ['name']
谢谢。
问候
编辑:
我想具体说明我的问题:
我只想在j中不存在项时添加它。因此,我需要检查“name”字段,如下所示:
[ {
"uri" : "/item/12947",
"version" : 1,
"tracker" : {
"uri" : "/category/73718",
"name" : "Instructions"
},
"priority" : {
"id" : 2,
"name" : "High",
"flags" : 0
},
"name" : "Testitem",
"status" : {
"id" : 1,
"name" : "New",
"flags" : 0
我怎样才能说:
if "Testitem" not in j: ... here i need to say that only the "name:" value needs to be checked....
print "Item does not exist and has been created"
else: print "Item already exists"
对于j中的条目:
如果“xyz”不在str(条目)中:
打印(条目)
只要在循环中使用if,就像if entry['name']!='然后打印条目
if "Testitem" not in j: ... here i need to say that only the "name:" value needs to be checked....
print "Item does not exist and has been created"
else: print "Item already exists"