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 = MiniJSONParser.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
            MiniJSONParser.lastDecode = json;

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

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

                return(value);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
 public static Hashtable hashtableFromJson(this string json)
 {
     return(MiniJSONParser.jsonDecode(json) as Hashtable);
 }
Exemplo n.º 4
0
 public static ArrayList arrayListFromJson(this string json)
 {
     return(MiniJSONParser.jsonDecode(json) as ArrayList);
 }
Exemplo n.º 5
0
 public static string toJson(this Dictionary <string, string> obj)
 {
     return(MiniJSONParser.jsonEncode(obj));
 }
Exemplo n.º 6
0
 public static string toJson(this Hashtable obj)
 {
     return(MiniJSONParser.jsonEncode(obj));
 }