可以使用Python的json库来解析JSON数据,并根据要求获取receiveId的值。

下面是实现的代码:

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数据
json_data = json.loads(data)

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

# 遍历tasks列表,将id和receiveId对应存入字典
id_receive_dict = {}
for task in tasks:
    id_receive_dict[task["id"]] = task["receiveId"]

# 输出id等于16的receiveId的值
receive_id_16 = id_receive_dict.get(16)
print(receive_id_16)

运行以上代码,输出为:14758674,即id等于16的receiveId的值

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

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

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