解析 onesignal API 响应

我想使用 PHP 解析来自 onesignal API 的响应。以下是 API 响应的结构。我想打印唯一的某些参数。我怎样才能做到这一点?


{

    "adm_big_picture": "",

    "adm_group": "",

    "adm_group_message": {

        "en": ""

    },

    "adm_large_icon": "",

    "adm_small_icon": "",

    "adm_sound": "",

    "spoken_text": {},

    "alexa_ssml": null,

    "alexa_display_title": null,

    "amazon_background_data": false,

    "android_accent_color": "FF9900FF",

    "android_group": "group key",

    "android_group_message": {

        "en": "group message for Android 6.0 and older"

    },

    "android_led_color": null,

    "android_sound": null,

    "android_visibility": 1,

    "app_id": "3beb3078-e0f1-4629-af17-fde833b9f716",

    "big_picture": "https://img.onesignal.com/n/37326fcc-2baa-45da-891c-ca9454a64957.png",

    "buttons": null,

    "canceled": false,

    "chrome_big_picture": "",

    "chrome_icon": "",

    "chrome_web_icon": "https://picture-resource.com/icon-image.png",

    "chrome_web_image": "https://picture-resource.com/image.png",

    "chrome_web_badge": "https://picture-resource.com/badge.png",

    "content_available": false,

    "contents": {

        "en": "English Message"

    },

    "converted": 1,

    "data": {

        "additional": "data",

        "campaign": "25"

    },

    "delayed_option": "immediate",

    "delivery_time_of_day": "2:32PM",

    "errored": 4,

    "excluded_segments": [],

    "failed": 0,

    "firefox_icon": "https://picture-resource.com/firefox_icon.png",

    "global_image": "https://link-to-your-image.com/image-resource-file.png",

    "headings": {

        "en": "English Message Title 😊"

    },

    "id": "fd1723c6-bfaf-4f53-b4f4-0408ff43e18a",

    "include_player_ids": null,

    "include_external_user_ids": null,

    "included_segments": [

        "Subscribed Users"

    ],

我只想打印某些参数,以便我可以做进一步的处理。但我无法解析响应。



阿晨1998
浏览 90回答 1
1回答

湖上湖

你的 JSON 是一个对象,而不是一个数组,所以(一旦你解码了它)你可以直接访问它的属性。直接扔掉[0]就没有问题了。echo "checking---".$yummy['app_id'];[0]如果 JSON 是一个数组并且您的数据位于该数组的第一个元素内,这将是有意义的。但是对于一个简单的对象,没有像这样的额外层要遍历。
打开App,查看更多内容
随时随地看视频慕课网APP