我想使用 PHP 解析來(lái)自 onesignal API 的響應(yīng)。以下是 API 響應(yīng)的結(jié)構(gòu)。我想打印唯一的某些參數(shù)。我怎樣才能做到這一點(diǎn)?{ "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" ],我只想打印某些參數(shù),以便我可以做進(jìn)一步的處理。但我無(wú)法解析響應(yīng)。
1 回答

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