using UnityEngine;
using System;
using System.Text;
using System.Security.Cryptography;
using UnityEngine.Events;
namespace TcgEngine
{
///
/// Useful tool static functions for the ApiClient
///
public class ApiTool : MonoBehaviour
{
// ----- Convertions ------
public static T JsonToObject(string json)
{
try
{
T value = JsonUtility.FromJson(json);
return value;
}
catch (Exception) { }
return (T)Activator.CreateInstance(typeof(T));
}
public static T[] JsonToArray(string json)
{
ListJson list = new ListJson();
list.list = new T[0];
try
{
string wrap_json = "{ \"list\": " + json + "}";
list = JsonUtility.FromJson>(wrap_json);
return list.list;
}
catch (Exception) { }
return new T[0];
}
public static string ToJson(object data)
{
return JsonUtility.ToJson(data);
}
public static int ParseInt(string int_str, int default_val = 0)
{
bool success = int.TryParse(int_str, out int val);
return success ? val : default_val;
}
}
}