Skip to main content
Version: 6.0.0

Deserialize

This is a way to deserialize unmarshalled data to class again.
Unmarshalled data can be easily deserialized using the BACKND.LitJson library.

Deserializing is a function that uses the BACKND.LitJson library, not a function provided by BACKND.
For more information, please refer to BACKND.LitJson API.

To properly deserialize to class, the following conditions should be met:

  • Variable to be included in the class returned after deserializing must be public.
  • The key value and class variable of the data looked up from the server must be the same(case-sensitive).
    If the key value of the looked-up data is 'Name' but the name of the class variable is 'name,' deserializing may fail depending on the running environment.

If the return value contains a key, but in class the relevant variable is non-existent or public, it will not be included in the result of deserialization.

example

public class Item
{
public string name = string.Empty;
public int atk = 0;
public int def = 0;
public double critical = 1.0;
public int[] socket = new int[3];
public Dictionary<string, string> option = new Dictionary<string, string>();
public override string ToString()
{
var arr = string.Join(", ", socket);
string dic = string.Join(", ", option.Select(x => x.Key + ":" + x.Value).ToArray());
return string.Format("name: {0}\tatk: {1}\tdef: {2}\tcriticla: {3}\tsocket: {4}\toption: {5}",
name, atk, def, critical, arr, dic);
}
}

public void Deserialize()
{
// Looks up 100 tables in the inventory
var bro = Backnd.GameInfo.GetPrivateContents("inventory", 100);
if(bro.IsSuccess() == false)
{
return;
}
// Unmarshalls the looked-up data
var json = BackndReturnObject.Flatten(bro.Rows());
for(int i=0; i<json.Count; ++i)
{
// Deserializes and checks the data
var item = BACKND.LitJson.JsonMapper.ToObject<Item>(json[i].ToJson());
Debug.Log(item.ToString());
}
}