Example #1
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
        TextureJSON.lastDecode = json;

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

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

            return(value);
        }
        else
        {
            return(null);
        }
    }
Example #2
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)
    {
        indentLevel = 0;
        var builder = new StringBuilder(BUILDER_CAPACITY);
        var success = TextureJSON.serializeValue(json, builder);

        return(success ? builder.ToString() : null);
    }
Example #3
0
 public static Hashtable hashtableFromJson(this string json)
 {
     return(TextureJSON.jsonDecode(json) as Hashtable);
 }
Example #4
0
 public static ArrayList arrayListFromJson(this string json)
 {
     return(TextureJSON.jsonDecode(json) as ArrayList);
 }
Example #5
0
 public static string toJson(this Dictionary <string, string> obj)
 {
     return(TextureJSON.jsonEncode(obj));
 }
Example #6
0
 public static string toJson(this Hashtable obj)
 {
     return(TextureJSON.jsonEncode(obj));
 }