gpt4 book ai didi

javascript - 从网络推送通知负载中获取值(value)

转载 作者:行者123 更新时间:2023-12-03 02:08:15 25 4
gpt4 key购买 nike

我从网络推送通知中收到了此有效负载。

{
"data": {
"notification": "{\"icon\":\"\\/static\\/assets\\/notifications\\/loader-100x100.png\",\"vibrate\":[200,100,200,100,200,100,400],\"tag\":\"request\",\"body\":\"12:30\",\"title\":\"HELLO\",\"actions\":[{\"icon\":\"\\/static\\/assets\\/notifications\\/loader-100x100.png\",\"action\":\"https:\\/\\/example.com\\/#done\",\"title\":\"OK\"},{\"icon\":\"\\/static\\/assets\\/notifications\\/loader-100x100.png\",\"action\":\"https:\\/\\/example.com\\/#open\",\"title\":\"Edit\"}]}"
},
"collapse_key": "do_not_collapse",
"from": "1111111"
}

如何获取title的值?我尝试了这个但没有运气:

var parsed = JSON.parse(payload);
const notificationTitle = parsed["notification"]["title"];

最佳答案

用那个对象就可以了

var parsedNotification = JSON.parse(payload.data.notification);
var title = parsedNotification.title;
console.log(title);

关于javascript - 从网络推送通知负载中获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49699724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com