Arrays Python引用数组中的每个JSON元素

Arrays Python引用数组中的每个JSON元素,arrays,json,Arrays,Json,我有一个JSON对象数组,如下所示。如何解析数组中的每个JSON对象 例如,我想解析{“事件”:“1”,“post_title”:“Test 5”,“ID”:“16”}并将其作为主体发送给API [ { "occurrences": "1", "post_title": "Test 5", "ID": "16" }, { "occurrences": "1", "post_title": "Test 6", "ID": "19"

我有一个JSON对象数组,如下所示。如何解析数组中的每个JSON对象

例如,我想解析
{“事件”:“1”,“post_title”:“Test 5”,“ID”:“16”}
并将其作为主体发送给API

  [
  {
    "occurrences": "1",
    "post_title": "Test 5",
    "ID": "16"
  },
  {
    "occurrences": "1",
    "post_title": "Test 6",
    "ID": "19"
  },
  {
    "occurrences": "1",
    "post_title": "xyz,abc",
    "ID": "21"
  }
]

将搜索到的参数添加到
变量中进行搜索。
如果条件逐个检查所有对象

import json

result = '[{"occurrences":"1","post_title":"Test 5","ID":"16"},{"occurrences":"1","post_title":"Test 6","ID":"19"},{"occurrences":"1","post_title":"xyz,abc","ID":"21"}]'

to_be_searched = {"occurrences": "1", "post_title": "Test 5", "ID": "16"}
result_arr = json.loads(result)

for res in result_arr:
    if res["occurrences"] == to_be_searched["occurrences"] and res["post_title"] == to_be_searched["post_title"] and \
            res["ID"] == to_be_searched["ID"]:
        print(res)
如果在执行上述代码时遇到任何问题,例如
AttributeError:module'json'没有属性'loads'

通过在终端上执行以下命令来安装simplejson模块
pip安装simplejson

对于蟒蛇3
pip3安装simplejson

只需将上述代码中的第一行更改为

将simplejson导入为json

欢迎使用SO,请发布您在上面所做的努力,并询问您在这样做时面临的错误。感谢您的回复。还有一个问题,我如何快速迭代数组中的每个JSON块,并将其作为主体发送给API?{“事件”:“1”,“文章标题”:“测试5”,“ID”:“16”}