Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]
  };
like image 812
Pavel Avatar asked Jan 16 '20 15:01

Pavel


Video Answer


1 Answers

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.

like image 59
Frank van Puffelen Avatar answered Sep 28 '22 02:09

Frank van Puffelen