下面是根据给定的JSON数据获取receiveId值并与id值做数组对应的Python代码:

import json

data = """
{
    "result_code": 0,
    "result": "操作成功",
    "data": {
        "tasks": [
            {
                "id": 16,
                "identifyingCode": "TASK02007",
                "taskName": "转发社区文章内容",
                "taskCode": "TASK02007",
                "picUrl": "https://img-rulife.bthhotels.com/rulife/16752298499947371.png",
                "taskDesc": "转发社区文章内容",
                "taskType": 2,
                "takeType": 1,
                "taskDate": "20230905",
                "partType": 1,
                "partNum": 1,
                "redirectUrl": "eventPackage/pages/hotel_around/index",
                "h5Url": "https://idea.homeinns.com/event/hotel_around/home/index",
                "isH5With": 0,
                "isRedirectWith": 1,
                "rewardDesc": "转发社区文章内容",
                "gv": null,
                "point": null,
                "couponList": null,
                "receiveId": 14758674,
                "taskStatus": 1,
                "taskNum": 0,
                "receiveStatus": 0,
                "urlType": 2,
                "urlUserType": "0",
                "displayType": 0,
                "h5UrlType": 1,
                "h5UrlUserType": "authcode",
                "isReceiveSelf": 0,
                "needCallBack": 1,
                "crowdType": 0,
                "crowdLevelCode": null,
                "ruyuan_bean": 20,
                "rainbow_bean": 0
            },
            {
                "id": 21,
                "identifyingCode": "TASK02003",
                "taskName": "成功使用如愿豆并入住",
                "taskCode": "TASK02003",
                "picUrl": "https://img-rulife.bthhotels.com/rulife/16752298943945362.png",
                "taskDesc": "成功使用如愿豆并入住",
                "taskType": 2,
                "takeType": 1,
                "taskDate": null,
                "partType": 3,
                "partNum": 3,
                "redirectUrl": "pages/hotel/index",
                "h5Url": "{\"android\":\"homeinn://hotellist?\",\"ios\":\"homeinns://hotellist\"}",
                "isH5With": 1,
                "isRedirectWith": 0,
                "rewardDesc": "成功使用如愿豆并入住",
                "gv": null,
                "point": null,
                "couponList": null,
                "receiveId": 0,
                "taskStatus": 0,
                "taskNum": 0,
                "receiveStatus": 0,
                "urlType": 2,
                "urlUserType": "0",
                "displayType": 0,
                "h5UrlType": 4,
                "h5UrlUserType": "authcode",
                "isReceiveSelf": 0,
                "needCallBack": 1,
                "crowdType": 0,
                "crowdLevelCode": null,
                "ruyuan_bean": 20,
                "rainbow_bean": 0
            },
            {
                "id": 37,
                "identifyingCode": "TASK02008",
                "taskName": "成功使用首免折扣券",
                "taskCode": "TASK02008",
                "picUrl": "https://img-rulife.bthhotels.com/rulife/1675229806654930.png",
                "taskDesc": "成功使用首免折扣券",
                "taskType": 2,
                "takeType": 1,
                "taskDate": null,
                "partType": 4,
                "partNum": 1,
                "redirectUrl": "userPackage/pages/my/coupons/index",
                "h5Url": "{\"android\":\"homeinns://UserCouponActivity?needLogin=true\",\"ios\":\"homeinns://TicketsViewController?needLogin=true\"}",
                "isH5With": 0,
                "isRedirectWith": 1,
                "rewardDesc": "成功使用首免折扣券",
                "gv": null,
                "point": null,
                "couponList": null,
                "receiveId": 0,
                "taskStatus": 0,
                "taskNum": 0,
                "receiveStatus": 0,
                "urlType": 2,
                "urlUserType": "0",
                "displayType": 0,
                "h5UrlType": 4,
                "h5UrlUserType": "authcode",
                "isReceiveSelf": 0,
                "needCallBack": 1,
                "crowdType": 0,
                "crowdLevelCode": null,
                "ruyuan_bean": 20,
                "rainbow_bean": 0
            }
        ],
        "act_bean": 17960,
        "ruyuan_bean": 1448
    }
}
"""

# 解析JSON数据
data_dict = json.loads(data)

# 获取tasks列表
tasks = data_dict["data"]["tasks"]

# 获取receiveId值并与id值做数组对应
receive_ids = [task["receiveId"] for task in tasks]
ids = [task["id"] for task in tasks]

# 打印结果
for receive_id, task_id in zip(receive_ids, ids):
    print(f"receiveId: {receive_id}, id: {task_id}")

这将打印出receiveId的值和相应的id值

PY 获取下面代码: result_code 0 result 操作成功 data tasks id 16 identifyingCode TASK02007 taskName 转发社区文章内容 tas

原文地址: http://www.cveoy.top/t/topic/iX1z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录