Error: "data must only contain string values" firebase cloud messaging

Error: "data must only contain string values" firebase cloud messaging

我正在尝试通过 FCM(Firebase 云消息传递)将一些数据从我的 node.js 服务器发送到 android 客户端。发送时出现以下错误:"data must only contain string values"。我的数据包含 2 个 JSONObject。我是否必须将它们转换为字符串或者去这里的方式是什么?谢谢

var message = {
    notification:{
        "title": "Alert!",
        "body": position[0] + " has left Area: " + activeGeofences[i][1].name
      },
      data:{
        Geofence: activeGeofences[i][1],
        Position: position[1]
      },
    token: activeGeofences[i][0]
  };

要将任何 JSON 对象转换为字符串,您可以使用 JSON.stringify()。在接收方,您可以使用 JSON.parse()(或您的平台的等效项)将字符串解析回树结构。

你也可以这样做,因为我觉得它更准确

data: {
       key1: "value1",
       key2: "value2",
        }

你只需要确保 value1 或 value2 或任何 n 键的值对是字符串,如果它是 int 或任何其他它会抛出错误。这可以使您免于解析。

内部数据对象数据类型应始终为字符串。
如果您将输入数字数据类型,则会发生错误。

let message = {
  notification: {
    title: payload.title,
    body: payload.message,
  },
  data: {
    name: 'sds',
    type: '2',
    _id: 'sdsd',
  },
  token: deviceToken,
};