I want to create a JSON Dictonary (key and value are both strings), that I can send via TCP. The second key contains a Class with just a single List of Objects. I try to convert it to JSON, so I am able to send it.
AllCharacterActions characterActions = new AllCharacterActions();
// fill List in this class with content
JsonDictionary send = new JsonDictionary ();
send ["command"] = "OrderedFightPlayersList";
send ["ClassWithList"] = JsonUtility.ToJson(characterActions);
But if I debug.Log the send ["ClassWithList"], it says {} . This is the code of the two classes. The second one is the one I try to convert. The first one is the Class that should be in the list (4 times). I know the list with the 4 classes is in it, before I convert it.
public class CharacterAction
{
public int[] targetID;
public int characterID;
public string itemName;
public string action;
}
[Serializable]
public class AllCharacterActions
{
public List<CharacterAction> allCharacterActions = new List<CharacterAction>();
public void Add(CharacterAction characterAction)
{
allCharacterActions.Add(characterAction);
}
}
I'm using C# and Unity.