Search code examples
androidnode.jsfirebase-cloud-messaging

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


I'm trying to send some data from my node.js server to an android client via FCM(Firebase Cloud Messaging). I get the following error: "data must only contain string values" when sending it. My data contains 2 JSONObjects. Do I have to convert them to strings or what is the way to go here? Thanks.

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]
  };

Solution

  • To convert any JSON objects to a string, you can use JSON.stringify(). On the receiving side you can then use JSON.parse() (or your platform's equivalent) to parse the string back into a tree structure.