public static T[] readArray <T>(string json) { string newJson = "{ \"array\": " + json + "}"; JsonArrayWrapper <T> wrapper = JsonUtility.FromJson <JsonArrayWrapper <T> > (newJson); return(wrapper.array); }
/// <summary> /// Converts an array of type T to a json string /// </summary> /// <typeparam name="T">The type of the array</typeparam> /// <param name="array">Array to conver to json data</param> /// <param name="prettyPrint">If true, the output will be printed in a way that is more human-readable</param> /// <returns>Json string</returns> public static string ToJson <T>(T[] array, bool prettyPrint) { JsonArrayWrapper <T> wrapper = new JsonArrayWrapper <T>(); wrapper.array = array; return(JsonUtility.ToJson(wrapper, prettyPrint)); }
/// <summary> /// Converts an array of type T to a json string /// </summary> /// <typeparam name="T">The type of the array</typeparam> /// <param name="array">Array to convert to json data</param> /// <returns>JSON string</returns> public static string ToJson <T>(T[] array) { JsonArrayWrapper <T> wrapper = new JsonArrayWrapper <T>(); wrapper.array = array; return(JsonUtility.ToJson(wrapper)); }
static public T[] ArrayFromJson <T>(string json) { json = "{ \"array\": " + json + "}"; string newJson = json; JsonArrayWrapper <T> wrapper = FromJson <JsonArrayWrapper <T> >(newJson); return((T[])wrapper.array); }
public static string ToJson <T>(T[] array) { var wrapper = new JsonArrayWrapper <T> { array = array, }; var json = JsonUtility.ToJson(wrapper); // Strip off the {"array":} stuff. return(json.Substring(9, json.Length - 9 - 1)); }
/// <summary> /// Converts a string to an array of the provided type /// </summary> /// <typeparam name="T">The array type to convert to</typeparam> /// <param name="json">The json string</param> /// <returns>Converted array of type T</returns> public static T[] FromJson <T>(string json) { JsonArrayWrapper <T> wrapper = JsonUtility.FromJson <JsonArrayWrapper <T> >(json); return(wrapper.array); }