Exemplo n.º 1
0
    /// <summary>
    /// Converts a Hashtable / ArrayList / Dictionary(string,string) object into a JSON string
    /// </summary>
    /// <param name="json">A Hashtable / ArrayList</param>
    /// <returns>A JSON encoded string, or null if object 'json' is not serializable</returns>
    public static string jsonEncode(object json)
    {
        var builder = new StringBuilder(BUILDER_CAPACITY);
        var success = MikuJson.serializeValue(json, builder);

        return(success ? builder.ToString() : null);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Parses the string json into a value
    /// </summary>
    /// <param name="json">A JSON string.</param>
    /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns>
    public static object jsonDecode(string json)
    {
        // save the string for debug information
        MikuJson.lastDecode = json;

        if (json != null)
        {
            char[] charArray = json.ToCharArray();
            int    index     = 0;
            bool   success   = true;
            object value     = MikuJson.parseValue(charArray, ref index, ref success);

            if (success)
            {
                MikuJson.lastErrorIndex = -1;
            }
            else
            {
                MikuJson.lastErrorIndex = index;
            }

            return(value);
        }
        else
        {
            return(null);
        }
    }
Exemplo n.º 3
0
    static public void LoadSpriteData(MikuAtlas atlas, TextAsset asset)
    {
        if (asset == null || atlas == null)
        {
            return;
        }

        string    jsonString  = asset.text;
        Hashtable decodedHash = MikuJson.jsonDecode(jsonString) as Hashtable;

        if (decodedHash == null)
        {
            Debug.LogWarning("Unable to parse Json file: " + asset.name);
        }
        else
        {
            LoadSpriteData(atlas, decodedHash);
        }

        asset = null;
        Resources.UnloadUnusedAssets();
    }