Ok so basically I am trying to get the hang of de-serializing and serializing custom classes in C# (unity) from strings. Json seemed to be the obvious method and is usable with mysql which I plan to use to store player data.
I can't get past a test string example I am trying to run to make a "Dummy" playerdata object. From there I will pass the player object to an Initialize method on the player at login.
Again I am just trying to use a (dummy) string (Which is the results of mysql queries right?) to generate a player data object. This is what I have.
PlayerData.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class PlayerData
{
public string Name {get; protected set;}
public uint Attack {get; protected set;}
public uint Defense {get; protected set;}
public uint Armor {get; protected set;}
public uint MovementSpeed {get; protected set;}
public uint MagicLevel {get; protected set;}
public static PlayerData Serialize(string obj)
{
return JsonUtility.FromJson<PlayerData>(obj);
}
}
the code I use to run it is this:
String test = @"{
""Name"": ""Chase"",
""Attack"" : 50,
""Defense"" : 35,
""Armor"" : 12,
""MovementSpeed"" : 60,
""MagicLevel"" : 15,
}";
PlayerData data = PlayerData.Serialize(test);
Debug.Log(data.Attack);
The error I get is this.
ArgumentException: JSON parse error: Missing a name for object member.
I really need help here, I have tried to ecapsulate the int variables with the double quotation marks, tried to do the same with all values, hell I have tried it so many ways, each time either that error or invalid value. Please any help would be much appreciated.