示例#1
0
        public static T[] readArray <T>(string json)
        {
            string newJson = "{ \"array\": " + json + "}";
            JsonArrayWrapper <T> wrapper = JsonUtility.FromJson <JsonArrayWrapper <T> > (newJson);

            return(wrapper.array);
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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));
        }
示例#4
0
    static public T[] ArrayFromJson <T>(string json)
    {
        json = "{ \"array\": " + json + "}";
        string newJson = json;
        JsonArrayWrapper <T> wrapper = FromJson <JsonArrayWrapper <T> >(newJson);

        return((T[])wrapper.array);
    }
示例#5
0
        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));
        }
示例#6
0
        /// <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);
        }