question

Mojo avatar image
Mojo asked

Jsonconvert enum as string.

Hi,

is there a way to serialize/deserialize an enum as a string with PlayFabSimpleJson?

(

like with newtonsoftjson =>

[JsonConverter(typeof(StringEnumConverter))]

public EEnum _enum;

)

Thanks.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

I assume you are using c# or Unity SDK. Enum is a value type data type in C# and its value will be converted to string if you are using PlayFab_Serializer in PluginManager via:

PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer) 

Here is an example, I am trying to serialize a list of "SetObject" object for SetObjects API

void Start() {
 var data = new Dictionary < string, object > () {
   {
    "Health", 100
   }, 
   {
    "Mana", test.max
   }
  };
 var dataList = new List < SetObject > () {
  new SetObject() {
    ObjectName = "PlayerData",
     DataObject = data
   }
 };
 string a = PlayFab.PluginManager.GetPlugin < ISerializerPlugin > (PluginContract.PlayFab_Serializer).SerializeObject(dataList);
 print(a);
}

public enum test
{
    max,
    medium,
    zero
}

You may see the test.max will be printed as "max".

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.