I have a class:
using System;
[Serializable]
public class GameMessage
{
public string cmd;
public object data;
public string seedId;
public string peerId;
public GameMessage( string cmd, object data, string seedId = null, string peerId = null )
{
this.cmd = cmd;
this.data = data;
this.seedId = seedId;
this.peerId = peerId;
}
}
And in some place at the code I calling:
JsonUtility.ToJson(new GameMessage("chat/say", "hello!"));
After this operation, I don’t have data property in result JSON.
The result is: {"cmd":"chat/say","seedId":"","peerId":""}
What’s wrong? Why data doesn’t appear in final JSON structure.
data
has any type. (possible string, custom object, float, array, etc…)