PushMessageData:json() 方法
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
备注: 此特性仅在 Service Worker 中可用。
PushMessageData
接口的 json()
方法通过将推送消息数据解析为 JSON 字符串并返回结果来提取推送消息数据。
语法
js
json()
参数
无。
返回值
将推送事件数据解析为 JSON 后的结果。这可以是任何可以用 JSON 表示的内容,例如对象、数组、字符串、数字等。
示例
js
self.addEventListener("push", (event) => {
const myData = event.data.json();
// 对你的数据进行处理
});
规范
Specification |
---|
Push API # dom-pushmessagedata-json |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
json |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.