我想使用 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" ],我只想打印某些參數,以便我可以做進一步的處理。但我無法解析響應。
1 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
你的 JSON 是一個對象,而不是一個數組,所以(一旦你解碼了它)你可以直接訪問它的屬性。直接扔掉[0]
就沒有問題了。
echo?"checking---".$yummy['app_id'];
[0]
如果 JSON 是一個數組并且您的數據位于該數組的第一個元素內,這將是有意義的。但是對于一個簡單的對象,沒有像這樣的額外層要遍歷。
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報
0/150
提交
取消