Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/Rest。检查条目是否已存在并执行某些操作_Python_Rest_For Loop_Python Requests - Fatal编程技术网

Python/Rest。检查条目是否已存在并执行某些操作

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/

我是python新手,希望执行以下操作:

我通过requests.get接收json。我想迭代它并打印所有没有“name”的条目:“xyz”

我有:

现在我想迭代j并说:只打印那些不是'name'的项目名称:'xyz'。比如:

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"