예제 #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 = MiniJSONL.serializeValue(json, builder);

        return(success ? builder.ToString() : null);
    }
예제 #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
        MiniJSONL.lastDecode = json;

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

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

            return(value);
        }
        else
        {
            return(null);
        }
    }
예제 #3
0
        public static Hashtable toHashtable(this JObject data)
        {
            string strJSON = data.ToString();

            if (string.IsNullOrEmpty(strJSON))
            {
                return(new Hashtable());
            }

            return(MiniJSONL.jsonDecode(strJSON) as Hashtable);
        }
예제 #4
0
        public static Hashtable toHashtable(this string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return(new Hashtable());
            }

            try
            {
                return(MiniJSONL.jsonDecode(json) as Hashtable);
            }
            catch (Exception ex) { }

            return(new Hashtable());
        }
예제 #5
0
 public static ArrayList toArrayList(this string json)
 {
     return(MiniJSONL.jsonDecode(json) as ArrayList);
 }
예제 #6
0
 public static string toJson(this ArrayList obj)
 {
     return(MiniJSONL.jsonEncode(obj));
 }
예제 #7
0
 public static string toJson(this IDictionary <string, object> obj)
 {
     return(MiniJSONL.jsonEncode(obj));
 }
예제 #8
0
 public static string toJson(this Hashtable obj)
 {
     return(MiniJSONL.jsonEncode(obj));
 }